There is not enough information to give a definitive answer to your question.
Think about what you would like if the day of the current month did not exist in your next month. Say January 31 + 1 month. (7 months of the year 31 days, while the rest have less). 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 heartily 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 have to 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 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 do the job after you have TDatetime that has the value you want:
procedure SetSystemDateTime(aDateTime: TDateTime); var lSystemTime: TSystemTime; lTimeZone: TTimeZoneInformation; begin GetTimeZoneInformation(lTimeZone); aDateTime := aDateTime + (lTimeZone.Bias / 1440); DateTimeToSystemTime(aDateTime, lSystemTime); setSystemTime(lSystemTime); end;
source share