Topic: last day of month
how can I set a datetimepicker always the last day of a month?
My Visual Database → General → last day of month
how can I set a datetimepicker always the last day of a month?
how can I set a datetimepicker always the last day of a month?
procedure Form1_OnShow (Sender: TObject; Action: string);
var
Days: integer = DaysInMonth(StrToInt(FormatDateTime('YYYY',NOW)),StrToInt(FormatDateTime('MM',NOW)));
begin
Form1.MonthCalendar1.Date := StrToDate(IntToStr(Days)+'.'+FormatDateTime('MM',NOW)+'.'+FormatDateTime('YYYY',NOW));
Form1.DateTimePicker1.DateTime := StrToDate(IntToStr(Days)+'.'+FormatDateTime('MM',NOW)+'.'+FormatDateTime('YYYY',NOW));
end;
For current date (month)
Form1.DateTimePicker1.Date := incmonth(Date, 1) - strtoint(FormatDateTime('d', incmonth(Date, 1)));
For any selected year month
Form1.DateTimePicker1.Date := incmonth(Form1.DateTimePicker1.Date, 1) - strtoint(FormatDateTime('d', incmonth(Form1.DateTimePicker1.Date, 1)));
and there will be no problems with the separator
Same for the calendar.
Thank's sparrow
it works fin.
Can you please explain to me the code. I really like to understand him.
For current date (month)
Form1.DateTimePicker1.Date := incmonth(Date, 1) - strtoint(FormatDateTime('d', incmonth(Date, 1)));
For any selected year month
Form1.DateTimePicker1.Date := incmonth(Form1.DateTimePicker1.Date, 1) - strtoint(FormatDateTime('d', incmonth(Form1.DateTimePicker1.Date, 1)));
and there will be no problems with the separator
Same for the calendar.
increase the month by 1 and subtract from the received value the received value of the days of the increased month.
All of this is calculated in a TDateTime (real) value.
If in understandable language then
1. 2023-06-26 + 1 month = 2023-07-26
2. 2023-07-26 ---> this is the 26th day of the 7th month
3. 2023-07-26 - 26 days = 2023-06-30
By the same principle, dates can be calculated in SQL.
Hi Sparrow,
Very nice! (I tried but it took me 4 steps )
Kudos to you.
Derek
Hi Derek
And here is the SQL
Form1.DateTimePicker1.Date := SQLDateTimeToDateTime(SQLExecute('SELECT date(''now'',''start of month'',''+1 month'',''-1 day'')'));
My Visual Database → General → last day of month
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi