bestlong 怕失憶論壇's Archiver

bestlong 發表於 2007-10-17 14:57

取得指定月份的第一天和最後一天的日期

[code]
//取得指定月份的第一天和最後一天的日期
//fdom回傳參數為日期所在月份的第一天的日期
//ldom回傳該月份的最後一天的日期(所給日期的下一個月的第一天日期減去一,很簡單吧!)

function fdom(date: tdatetime): tdatetime;
var
  year, month, day: word;
begin
  DecodeDate(date, year, month, day);
  result := EncodeDate(year, month, 1);
end;

function ldom(date: tdatetime): tdatetime;
var
  year, month, day: word;
begin
  DecodeDate(date, year, month, day);
  if month < 12 then Inc(month)
  else begin month := 1; Inc(year) end;
  result := EncodeDate(year, month, 1) - 1;
end;
[/code]

bestlong 發表於 2009-12-17 09:52

取得目前月的最後日期[code]function LastDayCurrMon: TDate;
begin
   result := EncodeDate(YearOf(Now), MonthOf(Now), DaysInMonth(Now)) ;
end;[/code]取得指定日期之當月的最後日期[code]function LastDayOfMon(date: TDateTime): TDate;
begin
   result := EncodeDate(YearOf(date), MonthOf(date), DaysInMonth(date)) ;
end;[/code]

bestlong 發表於 2012-9-12 13:37

[code]
var FirstDay, LastDay: TDateTime;

//本月第一天
FirstDay := StrToDate(FormatDateTime('yyyy-MM-01', Now));

//本月最後一天
LastDay := IncMonth(FirstDay) - 1;
[/code]
頁: [1]

Powered by Discuz! X1.5 Archiver   © 2001-2010 Comsenz Inc.