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

To add comments, please log in or register
pipspider
195
pipspider  

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.

Carl Schreiber
Moderator
8834
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()
pipspider
195
pipspider  
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.

nicholi shen
2392
nicholi shen  

You could also use the PeriodSeconds function


my_time+= 23 * PeriodSeconds(PERIOD_H1);
pipspider
195
pipspider  
nicholi shen:

You could also use the PeriodSeconds function


Oh yes good point, thank you @nicholi shen , helpful as always,
appreciate your time.

To add comments, please log in or register