I want to substract a day in:
string strTime = TimeYear(TimeCurrent()) + "." + TimeMonth(TimeCurrent()) + "." + TimeDay(TimeCurrent()) + " " + '22:41';
TheDate = StrToTime(strTime) - PERIOD_D1 ;
Alert(TimeToStr(TheDate));
If current day is 30 strTime = "2012.05.30 22:41" and TheDate should give "2012.05.30 22:41" but it isn't the case !
So HOW can I actually substract one day ?
Believe or not one day in MQL4 is
Alert (TimeToStr ((Time[0] - Time [1]), TIME_DATE|TIME_SECONDS)); // on daily chart //========================== datetime One_Day = StrToTime ("1970.01.02 00:00:00"); // this is what mql4 say about one day
Try it and update us with the result.
I want to substract a day in:
string strTime = TimeYear(TimeCurrent()) + "." + TimeMonth(TimeCurrent()) + "." + TimeDay(TimeCurrent()) + " " + '22:41';
TheDate = StrToTime(strTime) - PERIOD_D1 ;
Alert(TimeToStr(TheDate));
If current day is 30 strTime = "2012.05.30 22:41" and TheDate should give "2012.05.30 22:41" but it isn't the case !
So HOW can I actually substract one day ?
PERIOD_D1 represents the number of minutes in a day ( = 1440 ) whilst datetime variables and calculations are based on seconds. If you want to subtract 1 day from another datetime value then just subtract (PERIOD_D1 * 60) which is 1440 * 60 or 86400, the number of seconds in a day.
Regards, Paul.
You could subtracts this one day instead . . .
datetime OneDay = PERIOD_D1 * 60;
PERIOD_D1 represents the number of minutes in a day ( = 1440 ) whilst datetime variables and calculations are based on seconds. If you want to subtract 1 day from another datetime value then just subtract (PERIOD_D1 * 60) which is 1440 * 60 or 86400, the number of seconds in a day.
Regards, Paul.
LOL
TimeToStr (PERIOD_D1 * 60, TIME_DATE|TIME_SECONDS) == "1970.01.02 00:00:00"
Just like me reply above.
I want to substract a day in:
- Do you really? What if yesterday was the weekend or a holiday?
datetime now = TimeCurrent(), yesterday = now - 86400; // PERIOD_D1 * 60
- If you want the last trading datetime
datetime now = TimeCurrent(), tod = now % 86400, yesterday = iTime(NULL, PERIOD_D1, 1), todYesterday = yesterday + tod;

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to substract a day in:
string strTime = TimeYear(TimeCurrent()) + "." + TimeMonth(TimeCurrent()) + "." + TimeDay(TimeCurrent()) + " " + '22:41';
TheDate = StrToTime(strTime) - PERIOD_D1 ;
Alert(TimeToStr(TheDate));
If current day is 30 strTime = "2012.05.30 22:41" and TheDate should give "2012.05.30 22:41" but it isn't the case !
So HOW can I actually substract one day ?