How do you do date maths
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How do you do date maths
how do you add a number of days to the system date so the correct future date results?
Re: How do you do date maths
The easiest way is to use dateitems.
Convert the date to dateitems, then add your days to item 3 (which I believe is days) then convert back.
Convert the date to dateitems, then add your days to item 3 (which I believe is days) then convert back.
Re: How do you do date maths
As Sturgis said, dateItems gives you direct access to such things as the day of the week, month, year, etc.
But often, as you say, to do maths on the date, it is better to use "the seconds". This is a counter that started in 1970, and can be used to calculate dates directly.
So knowing that each day has 86,400 seconds is a way to find or set times and dates anytime in the past or future. The two are frequently used together, since converting from one format to the other is straightforward, and you can crunch your data in any way. Experiment with both, and convert from one to the other. These are very powerful tools.
Craig Newman
But often, as you say, to do maths on the date, it is better to use "the seconds". This is a counter that started in 1970, and can be used to calculate dates directly.
So knowing that each day has 86,400 seconds is a way to find or set times and dates anytime in the past or future. The two are frequently used together, since converting from one format to the other is straightforward, and you can crunch your data in any way. Experiment with both, and convert from one to the other. These are very powerful tools.
Craig Newman
Re: How do you do date maths
Using the seconds works well, the only thing you might have to watch out for is strangeness due to daylight savings time. Sometimes after you convert the date (which turns it into seconds for that date based at 12:00 PM) do your calcs, then turn it back in, losing the hour of daylight savings time will make the answer off by one hour. Easiest way to avoid this is add a couple hours to the seconds after the first convert.
Re: How do you do date maths
I plumped for the seconds, because in my particular case (point taken about the drift) there is only going to be a year max, between dates.
All helpfull answers and gives the pros and cons for different uses.
Thank you for the help.
All helpfull answers and gives the pros and cons for different uses.
Thank you for the help.