Home > Back-end >  Delphi how to determine the date for the whole month?
Delphi how to determine the date for the whole month?

Time:09-22

The 2016-07-01 ~ 2016-07-01 month
The 2016-08-05 ~ 2016-08-05 a month
The 2016-09-12 ~ 2016-09-12 a month
The 2016-02-01 ~ 2016-02-01 a month

Is this meaning, how to do?

CodePudding user response:

In a month on the first day of the date and the last day of the date, then compare,

CodePudding user response:

Whether dates vary the number of days is equal to the number of days of the month

CodePudding user response:

There is no better way??

CodePudding user response:

The following code for reference:
 
Procedure TMDI_1_1_Frm. Button8Click (Sender: TObject);
Var S, Date1 and Date2: string;
The begin
S:='2016-08-05 ~ ~ 2016-08-05';
Date1:=Copy (S, 1, 10);
Date2=Copy (S, 13, 18);
If (StartOfTheMonth (StrToData (Date1))=StrToData (Date1)) and
(EndOfTheMonth (StrToDate (Date2))=StrToData (Date1))
Then showMessage (' a whole month! ')
The else showMessage (' the whole month! L ')
end;


Be careful to USES DateUtils unit;

CodePudding user response:

Brother, can try ShowMessage (DatetoStr (StartofTheMonth (date1)));
What is value?



This is the result of I,

CodePudding user response:

Date1:=2016-07-01;
Date2:=2016-07-31;
ShowMessage (DatetoStr (StartofTheMonth (date1)));

CodePudding user response:

If DayOfTheMonth (nDate + 1)=1 then
A whole month

CodePudding user response:

Variables:
Date1: Tdatetime;
S: a string;

Assignment:
Date1:=2016-07-01;
S:='2016-07-01';

The return value:
Showmessage (inttostr (DayOfTheMonth (date1)); - return 30??????
Showmessage (inttostr (DayOfTheMonth (strtodatetime (s)))); - return 1

Why??

CodePudding user response:

If the date1 assignment for the 2016-02-29 (this year is a leap year)
Showmessage (inttostr (DayOfTheMonth (date1 + 1))); - return to 8??????????


If the assignment for '2016-02-29' s
Showmessage (inttostr (DayOfTheMonth (strtodatetime (s) + 1))); - the return value is 1

Not accurate as character of type date???????

CodePudding user response:

Simple.
Add 1 day is the first day of next month,

CodePudding user response:

 var 
Sdate, date1 and date2: string;
The begin
Sdate:='2016-02-01 ~ ~ 2016-02-01';
Date1:=Copy (Sdate, 1, 10);
Date2=Copy (Sdate, 13, 18);
If (dayof (strtodate (date1) & lt;> (1) or (dayof incday (strtodate (date2))) & lt;> 1)
Then
Showmessage (' the whole month ')
The else
Showmessage (' month ');
end;

CodePudding user response:

reference 4 floor lyhoo163 response:
code below for reference:
 
Procedure TMDI_1_1_Frm. Button8Click (Sender: TObject);
Var S, Date1 and Date2: string;
The begin
S:='2016-08-05 ~ ~ 2016-08-05';
Date1:=Copy (S, 1, 10);
Date2=Copy (S, 13, 18);
If (StartOfTheMonth (StrToData (Date1))=StrToData (Date1)) and
(EndOfTheMonth (StrToDate (Date2))=StrToData (Date1))
Then showMessage (' a whole month! ')
The else showMessage (' the whole month! L ')
end;


Be careful to USES DateUtils unit;


Floor tried, approved by the test!
  • Related