I've looked into TimeCurrent() as well as CDatetime and I can't seem to figure out to determine the number of seconds elapsed in a day. I like
TimeCurrent(), but I would prefer to have only the time without the date. I need to obtain the number of seconds elapsed as opposed to just the
time as a string.
- Is there a better way to add and substact Date Time values
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- [WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you.
Westie30:
I've looked into TimeCurrent() as well as CDatetime and I can't seem to figure out to determine the number of seconds elapsed in a day. I like TimeCurrent(), but I would prefer to have only the time without the date. I need to obtain the number of seconds elapsed as opposed to just the time as a string.
I just figured out to do (long)TimeCurrent(), but what exactly does this number mean? Does it include hours, minutes, and seconds? If so, how do
I get seconds only?
I've looked into TimeCurrent() as well as CDatetime and I can't seem to figure out to determine the number of seconds elapsed in a day. I like TimeCurrent(), but I would prefer to have only the time without the date. I need to obtain the number of seconds elapsed as opposed to just the time as a string.
I think the Time is seconds from 1900-01-01
So if you take TimeCurrent() and minus StrToTime("00:00") you'll be left with the seconds so far for the day
StrToTime will default to today's date if you don't specific one
please refer to https://www.mql5.com/en/docs/constants/structures/mqldatetime

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Date Type Structure
- www.mql5.com
Constants, Enumerations and Structures / Data Structures / Date Type Structure - Reference on algorithmic/automated trading language for MetaTrader 5
Westie30:
I just figured out to do (long)TimeCurrent(), but what exactly does this number mean? Does it include hours, minutes, and seconds? If so, how do I get seconds only?
I just figured out to do (long)TimeCurrent(), but what exactly does this number mean? Does it include hours, minutes, and seconds? If so, how do I get seconds only?
This is seconds since Epoch, the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).
You can convert a datetime to a MqlDateTime:
MqlDateTime time; TimeToStruct(TimeCurrent(),time); int Year = time.year; // Year int Month = time.mon; // Month int Day = time.day; // Day int Hour = time.hour; // Hour int Minute = time.min; // Minutes int Second = time.sec; // Seconds int Day_of_Week = time.day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) int Day_of_year = time.day_of_year; // Day number of the year (January 1st is assigned the number value of zero)
Now your seconds are an Integer.
Marco vd Heijden:
Thank you, that works great!
This is seconds since Epoch, the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).
You can convert a datetime to a MqlDateTime:
Now your seconds are an Integer.
Westie30: I've looked into TimeCurrent() and I can't seem to figure out to determine
the number of seconds elapsed in a day.
Find bar of
the same time one day ago - MQL4 programming forum

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register