Skip to content

Date and Time

Date and Time

This is the group of functions for working with data of datetime type (an integer that represents the number of seconds elapsed from 0 hours of January 1, 1970).

To arrange high-resolution counters and timers, use the GetTickCount() function, which produces values in milliseconds.

FunctionAction
TimeCurrentReturns the last known server time (time of the last quote receipt) in the datetime format
TimeLocalReturns the local computer time in datetime format
TimeGMTReturns GMT in datetime format with the Daylight Saving Time by local time of the computer, where the client terminal is running
TimeDaylightSavingsReturns the sign of Daylight Saving Time switch
TimeGMTOffsetReturns the current difference between GMT time and the local computer time in seconds, taking into account DST switch
TimeToStructConverts a datetime value into a variable of MqlDateTime structure type
StructToTimeConverts a variable of MqlDateTime structure type into a datetime value
DayReturns the current day of the month, i.e., the day of month of the last known server time
DayOfWeekReturns the current zero-based day of the week of the last known server time
DayOfYearReturns the current day of the year i.e., the day of year of the last known server time
HourReturns the hour of the last known server time by the moment of the program start
MinuteReturns the current minute of the last known server time by the moment of the program start
MonthReturns the current month as number, i.e., the number of month of the last known server time
SecondsReturns the amount of seconds elapsed from the beginning of the current minute of the last known server time by the moment of the program start
TimeDayReturns the day of month of the specified date
TimeDayOfWeekReturns the zero-based day of week of the specified date
TimeDayOfYearReturns the day of year of the specified date
TimeHourReturns the hour of the specified time
TimeMinuteReturns the minute of the specified time
TimeMonthReturns the month number of the specified time
TimeSecondsReturns the amount of seconds elapsed from the beginning of the minute of the specified time
TimeYearReturns year of the specified date
YearReturns the current year, i.e., the year of the last known server time

What’s new in MQL5

Added the MqlDateTime structure containing eight int type fields:

struct MqlDateTime
  {
   int year;           // year
   int mon;            // month
   int day;            // day
   int hour;           // hour
   int min;            // minutes
   int sec;            // seconds
   int day_of_week;    // day of week (0 - Sunday, 1 - Monday, ..., 6 - Saturday)
   int day_of_year;    // number of a day in a year (January 1 has number 0)
  };

Thus, the new TimeToStruct() and StructToTime() functions allow you to receive and pass data on days, hours, minutes and seconds within a single call.

Last updated on