Home > Back-end >  After choose DateTimePicker1 DateTimePicker2 will is the last day of the month.
After choose DateTimePicker1 DateTimePicker2 will is the last day of the month.

Time:02-14

DateTimePicker1. Date:=StartofTheMonth (Now);//get the first day of this month
DateTimePicker2. Date:=EndOfTheMonth (Now);//get the
the last day of this month
When DateTimePicker1 changed, for example, chose on March 15, then it is DateTimePicker2 is March 31, how to do?
Is DateTimePicker2 is always at the end of the last day of is determined according to the DateTimePicker1 choice which month is the last day of

CodePudding user response:

CodePudding user response:

Procedure TForm1. Button1Click (Sender: TObject);
The function the IIF (aCondition: Boolean; TrueValue falseValue: Variant) : the Variant;
The begin
If aCondition then
Result:=trueValue
The else
Result:=falseValue;
end;
Var
IYear, iMonth: Integer;
SLastDay: String;
The begin
//1 minus 1 next month is the last day of this month
//December next month is January 1 next year's
IYear:=YearOf (DateTimePicker1. Date);
IMonth=MonthOf (DateTimePicker1. Date);
SLastDay:=IntToStr (IIF (iMonth=12, iYear + 1, iYear)) + '-' +
IntToStr (IIF (iMonth iMonth=12, 1, + 1)) + '-' +
'1'.
SLastDay:=DateToStr (StrToDate (sLastDay) - 1);
DateTimePicker2. Date:=StrToDate (sLastDay);
Date of Application. MessageBox (PChar (Format (' : % s to % s' at the end of the, [DateToStr (DateTimePicker1. Date), sLastDay])), 'tip');
end;
  • Related