# Is there a better way to add and substact Date Time values

195

Hello guys,

Adding and subtracting datetime value within a single day can be done without any problem but doing such calculations which leaks into next day or previous day give some erroneous results.

For Example I want to find out the time after adding TimeCurrent() + 23 hours, how to do it?
At the moment the way I do it is by making a date time struct out of the current time and adding hours into the structVariable.hour if it is greater than 23, adding 1 to the structVariable.day.

Is there an easy way to do this.

Also is there a way to convert between times, Day to Hours etc.

Thank you very much.

Moderator
8834

As time is "the number of seconds elapsed since January 01, 1970." (see reference just seach for datetime) you have to add 23 * 60 * 60 seconds to TimeCurrent()
195

Carl Schreiber:
As time is "the number of seconds elapsed since January 01, 1970." (see reference just seach for datetime) you have to add 23 * 60 * 60 seconds to TimeCurrent()

That's the way to do it.

Thank you very much for your time.

2392

You could also use the PeriodSeconds function

`my_time+= 23 * PeriodSeconds(PERIOD_H1);`
195

nicholi shen:

You could also use the PeriodSeconds function

Oh yes good point, thank you @nicholi shen , helpful as always,