Determining time of day
- 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.
- [Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2.
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
- www.mql5.com
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.
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.