Date and Time Arithmetic

 
How to add or subtract days or minutes from a MQL5 Time Structure ?
 
chandra100:
How to add or subtract days or minutes from a MQL5 Time Structure ?
Convert to seconds then add or subtract . . .  do you understand what a datetime type variable is ?  look it up.
 
RaptorUK:
Convert to seconds then add or subtract . . .  do you understand what a datetime type variable is ?  look it up.

I dont think ur idea will work.

 
chandra100:

I dont think ur idea will work.

Maybe I misunderstood your question then,  why will it not work ?
 
,RaptorUK:
Maybe I misunderstood your question then,  why will it not work ?

Assume the present date is Feb 28 and time is 23:00.    

If I like to add 2 hours, it has to change all the three of hour part , day part and month part of datetime strucrure.

Leap year factor should also be taken into account.

converting into seconds won't do any purpose. 

 
chandra100:

Assume the present date is Feb 28 and time is 23:00.    

If I like to add 2 hours, it has to change all the three of hour part , day part and month part of datetime strucrure.

Leap year factor should also be taken into account.

converting into seconds won't do any purpose. 

OK,  I did understand your question correctly,  if you have Feb 28th 23:00 saved in a datetime variable and you want to add 2 hours all you do is add  2 * 60 * 60 to the variable.  You don't need to be concerned with leap years.  when you use TimeToString() with this variable and Print() it you will see the correct date and time . . .
 

https://www.mql5.com/en/forum/7986

I asked something similar before 

ObjectCreate
ObjectCreate
  • www.mql5.com
I have the codes to draw a horizontal trend line.
 
 
angevoyageur:
See this article.
That was fine.