Try this :
datetime TimeNow = TimeCurrent(); Print ( "TimeNow = ", TimeNow ); int AddNumber = 68; // in minute datetime AddTime = TimeNow + AddNumber*60; Print ( "AddTime = ", AddTime );
1.) Change the time to be added or substracted to seconds
2.) change the time 6:04 from string to time format
3.) Carry out the operation
int TimeToAdd=68*60; // change minutes to seconds datetime NewTime=StrToTime("6:04")+TimeToAdd; // Change time to datetime from string(hh:mm) format and carry out addition string NewEasyToReadTime=TimeToStr(NewTime); // Revert new time to string format of hh:mm:ss
Hi there, How can i input time in hours on screen.
similar to c programming , scanf.....
Hi there, How can i input time in hours on screen.
similar to c programming , scanf.....
https://docs.mql4.com/dateandtime/hour
Thank you, it possible to time display on Screen and user keys in required time. example: (Time: user keys in desired time, example , 10.00).
Hi Guys
How do you add or subtract time in MQL4?
eg if I wanted to add or subtract 68 minutes to/from 06:04
Thanks in advance
Jay
string time = h+":"+m;
Print ( "Time = ", time );
This will work, in the above 30minutes have been added to current time.
int h=TimeHour(TimeCurrent()); int m=TimeMinute(TimeCurrent()); m=m+30; string time = h+":"+m; Print ( "Time = ", time );
This will work, in the above 30minutes have been added to current time.
- When you post code please use the CODE button
(Alt-S)! (For large amounts of code, attach it.)
Please edit
your (original) post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - It doesn't add 30 minutes it adds 30 seconds.
- If the current time is 10:40 and you do m=m+30*60 you will display 10:70 "This will not work."
- When you post code please use the CODE button
(Alt-S)! (For large amounts of code, attach it.)
Please edit
your (original) post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - It doesn't add 30 minutes it adds 30 seconds.
- If the current time is 10:40 and you do m=m+30*60 you will display 10:70 "This will not work."
William, thank you for correcting me.
Am unable to edit the previous post.
few corrections made to previous code and now it will work
int h = TimeHour(TimeCurrent()); int m = TimeMinute(TimeCurrent()); m=m+30; int s = TimeSeconds(TimeCurrent()); string time,hh,mm,ss; hh = h; mm = m; ss = s; if (m > 59) { int t1 = m - 60; mm = t1; hh = h+1; } time = hh+":"+mm+":"+ss;
- nope. 23:40 + 30 minutes is not 24:10, it's 00:10.
- Buy why not just add the 30 minutes and format the new datetime how you want it.
string time = TimeToString(TimeCurrent() + 30*60, TIME_SECONDS);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Guys
How do you add or subtract time in MQL4?
eg if I wanted to add or subtract 68 minutes to/from 06:04
Thanks in advance
Jay