# Determining time of day

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.

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 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

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?

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:

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.

Thank you, that works great!

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