What do you want if the day of the current month does not exist in your next month? Say January 31 + 1 month? You have the same problem if you increase the year, and the starting date is February 29 in a leap year. Thus, there cannot be a universal IncMonth or IncYear function that will work continuously on all dates.
For anyone interested, I wholeheartedly recommend Julian Bucknall 's article on the complexities inherent in this type of computation on how to calculate the number of months and days between two dates.
Listed below are the only common date increment functions that do not introduce anomalies in general date math. But it only does this, shifting the responsibility back to the programmer, who supposedly has exact requirements for the specific application that he / she is programming.
IncDay - Add or subtract a few days.
IncWeek - Add or subtract a few weeks.
But if you must use the built-in functions, then at least make sure that they do what you want them to do. Take a look at the DateUtils and SysUtils modules. Having the source code for these features is one of the coolest aspects of Delphi. Having said that, here is a complete list of built-in functions:
IncDay - Add or subtract a few days.
IncWeek - Add or subtract a few weeks.
IncMonth - Add or subtract a few months.
IncYear - add or subtract a few years.
Regarding the second part of your question, how to set the system date and time using TDatetime, the following shamelessly stolen code from another message will perform the following task:
procedure SetSystemDateTime(aDateTime: TDateTime); var lSystemTime: TSystemTime; lTimeZone: TTimeZoneInformation; begin GetTimeZoneInformation(lTimeZone); aDateTime := aDateTime + (lTimeZone.Bias / 1440); DateTimeToSystemTime(aDateTime, lSystemTime); setSystemTime(lSystemTime); end;
user26293
source share