The start and end of each year, month, week, and Day in Delphi

Source: Internet
Author: User

Startofayear ... Startoftheyear ... Endofayear ... Endoftheyear ... The start and end times of each year, month, week, day

{参数是指定的年、月、周、日}
DateUtils.StartOfAYear
DateUtils.StartOfAMonth
DateUtils.StartOfAWeek
DateUtils.StartOfADay

{参数是 TDateTime}
DateUtils.StartOfTheYear
DateUtils.StartOfTheMonth
DateUtils.StartOfTheWeek
DateUtils.StartOfTheDay

{参数是指定的年、月、周、日}
DateUtils.EndOfAYear
DateUtils.EndOfAMonth
DateUtils.EndOfAWeek 
DateUtils.EndOfADay

{参数是 TDateTime}
DateUtils.EndOfTheYear
DateUtils.EndOfTheMonth
DateUtils.EndOfTheWeek
DateUtils.EndOfTheDay

Unit Unit1;

Interface

Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;

Type
TForm1 = Class (Tform)
Procedure Formcreate (Sender:tobject);
End

Var
Form1:tform1;

Implementation

{$R *.DFM}

Uses dateutils;

Procedure Tform1.formcreate (Sender:tobject);
Var
Dt,t1,t2,t3,t4:tdatetime;
s1,s2,s3,s4:string;
Begin
DT: = Strtodatetime (' 2009-5-20 11:22:33 ');

T1: = Startofayear (2009);
T2: = startoftheyear (DT);
T3: = Endofayear (2009);
T4: = endoftheyear (DT);

S1: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T1); 2009-1-1 0:0:0:000
S2: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T2); 2009-1-1 0:0:0:000
S3: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T3); 2009-12-31 23:59:59:999
S4: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T4); 2009-12-31 23:59:59:999

T1: = Startofamonth (2009, 5); {May 2009}
T2: = startofthemonth (DT);
T3: = Endofamonth (2009, 5);
T4: = endofthemonth (DT);

S1: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T1); 2009-5-1 0:0:0:000
S2: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T2); 2009-5-1 0:0:0:000
S3: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T3); 2009-5-31 23:59:59:999
S4: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T4); 2009-5-31 23:59:59:999


T1: = Startofaweek (2009, 21); {2009 21st Week}
T2: = Startoftheweek (DT);
T3: = Endofaweek (2009, 21);
T4: = endoftheweek (DT);

S1: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T1); 2009-5-18 0:0:0:000
S2: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T2); 2009-5-18 0:0:0:000
S3: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T3); 2009-5-24 23:59:59:999
S4: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T4); 2009-5-24 23:59:59:999

T1: = Startofaday (2009, 140); {2009 140th Day}
T2: = startoftheday (DT);
T3: = Endofaday (2009, 140);
T4: = endoftheday (DT);

S1: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T1); 2009-5-20 0:0:0:000
S2: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T2); 2009-5-20 0:0:0:000
S3: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T3); 2009-5-20 23:59:59:999
S4: = FormatDateTime (' yyyy-m-d h:n:s:zzz ', T4); 2009-5-20 23:59:59:999
End

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.