type
TDayTable = array [1..12] of Word;
PDayTable = ^TDayTable;function IsLeapYear(Year: Word): Boolean;
begin
Result := (Year mod 4 = 0) and
((Year mod 100 <> 0) or
(Year mod 400 = 0));
end;function GetDayTable(Year: Word): PDayTable;
const
DayTable1: TDayTable =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
DayTable2: TDayTable =
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
DayTables: array[Boolean] of PDayTable = (@DayTable1, @DayTable2);
begin
Result := DayTables[IsLeapYear(Year)];
end;function DaysInMonth(Year, Month: Word): Word;
begin
Result := GetDayTable(Year)[Month];
end;function Month(Date: TDateTime): Word;
var
D, M, Y: Word;
begin
DecodeDate(Date, Y, M, D);
Result := M;
end;function Year(Date: TDateTime): Word;
var
D, M, Y: Word;
begin
DecodeDate(Date, Y, M, D);
Result := Y;
end;function AddDays(Date: TDateTime; Days: Word): TDateTime;
begin
Result := Date + Days;
end;function AddMonths(Date: TDateTime; Months: Word): TDateTime;
var
TotalDays, CurrentMonth, CurrentYear: Word;
begin
TotalDays := 0;
CurrentMonth := Month(Date);
CurrentYear := Year(Date);
while Months > 0 do
begin
Inc(TotalDays, DaysInMonth(CurrentYear, CurrentMonth));
if CurrentMonth = 12 then
begin
CurrentMonth := 1;
Inc(CurrentYear);
end
else
Inc(CurrentMonth);
Dec(Months);
end;
Result := Date + TotalDays;
end;
function AddYears(Date: TDateTime; Years: Word): TDateTime;
var
TotalDays, CurrentYear: Word;
begin
TotalDays := 0;
CurrentYear := Year(Date);
while Years > 0 do
begin
if IsLeapYear(Year(CurrentYear)) then Inc(TotalDays, 366) else
Inc(TotalDays, 365);
Inc(CurrentYear);
Dec(Years);
end;
Result := Date + TotalDays;
end;
function DateAdd(Date: TDateTime; Y, M, D: Word): TDateTime;
begin
Result := AddYears(AddMonths(AddDays(Date, D), M), Y);
end;
TDayTable = array [1..12] of Word;
PDayTable = ^TDayTable;function IsLeapYear(Year: Word): Boolean;
begin
Result := (Year mod 4 = 0) and
((Year mod 100 <> 0) or
(Year mod 400 = 0));
end;function GetDayTable(Year: Word): PDayTable;
const
DayTable1: TDayTable =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
DayTable2: TDayTable =
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
DayTables: array[Boolean] of PDayTable = (@DayTable1, @DayTable2);
begin
Result := DayTables[IsLeapYear(Year)];
end;function DaysInMonth(Year, Month: Word): Word;
begin
Result := GetDayTable(Year)[Month];
end;function Month(Date: TDateTime): Word;
var
D, M, Y: Word;
begin
DecodeDate(Date, Y, M, D);
Result := M;
end;function Year(Date: TDateTime): Word;
var
D, M, Y: Word;
begin
DecodeDate(Date, Y, M, D);
Result := Y;
end;function AddDays(Date: TDateTime; Days: Word): TDateTime;
begin
Result := Date + Days;
end;function AddMonths(Date: TDateTime; Months: Word): TDateTime;
var
TotalDays, CurrentMonth, CurrentYear: Word;
begin
TotalDays := 0;
CurrentMonth := Month(Date);
CurrentYear := Year(Date);
while Months > 0 do
begin
Inc(TotalDays, DaysInMonth(CurrentYear, CurrentMonth));
if CurrentMonth = 12 then
begin
CurrentMonth := 1;
Inc(CurrentYear);
end
else
Inc(CurrentMonth);
Dec(Months);
end;
Result := Date + TotalDays;
end;
function AddYears(Date: TDateTime; Years: Word): TDateTime;
var
TotalDays, CurrentYear: Word;
begin
TotalDays := 0;
CurrentYear := Year(Date);
while Years > 0 do
begin
if IsLeapYear(Year(CurrentYear)) then Inc(TotalDays, 366) else
Inc(TotalDays, 365);
Inc(CurrentYear);
Dec(Years);
end;
Result := Date + TotalDays;
end;
function DateAdd(Date: TDateTime; Y, M, D: Word): TDateTime;
begin
Result := AddYears(AddMonths(AddDays(Date, D), M), Y);
end;
解决方案 »
- 做播放器播放wmv格式的视频,有什么方法可以边下载边播放?
- 用ADO,adoquery中的数据来源于多个数据表,如何实现更新时只更新其中的某一个表?
- 这样在memo中调用FindDialog进行查找
- OUTPUT参数问题??请高手帮忙看一下!!!
- 标识种子怎么写到数据库?
- 有谁知道?
- the decisioncube capacity is low,plese deactivate dimensions or change the data
- 如何用Delphi读取windows的安全日志?
- 调用vc做的dll的问题
- 如何控制程序的执行?
- 学delphi这么久,不敢问问题,因为太简单了,555,今天晚上有流星雨,准备看的朋友过来报道,上次流星雨没有给分呵呵,这次要给了!!
- 怎么用delphi,往快速启动栏中添加快捷方式。
incmonth(strtodate('2001-01-01'),1)就是2001-02-01日
incmonth(strtodate('2001-01-01'),1*12)就是2002-01-01日
incmonth(strtodate('2001-01-01'),1)就是2001-02-01日
incmonth(strtodate('2001-01-01'),1*12)就是2002-01-01日
{ Increment/decrement datetime fields }function IncYear(const AValue: TDateTime;
const ANumberOfYears: Integer = 1): TDateTime;
// function IncMonth is in SysUtils
function IncWeek(const AValue: TDateTime;
const ANumberOfWeeks: Integer = 1): TDateTime;
function IncDay(const AValue: TDateTime;
const ANumberOfDays: Integer = 1): TDateTime;
function IncHour(const AValue: TDateTime;
const ANumberOfHours: Int64 = 1): TDateTime;
function IncMinute(const AValue: TDateTime;
const ANumberOfMinutes: Int64 = 1): TDateTime;
function IncSecond(const AValue: TDateTime;
const ANumberOfSeconds: Int64 = 1): TDateTime;
function IncMilliSecond(const AValue: TDateTime;
const ANumberOfMilliSeconds: Int64 = 1): TDateTime;