MQL4 Reference 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.

Function

Action

TimeCurrent

Returns the last known server time (time of the last quote receipt) in the datetime format

TimeLocal

Returns the local computer time in datetime format

TimeGMT

Returns GMT in datetime format with the Daylight Saving Time by local time of the computer, where the client terminal is running

TimeDaylightSavings

Returns the sign of Daylight Saving Time switch

TimeGMTOffset

Returns the current difference between GMT time and the local computer time in seconds, taking into account DST switch

TimeToStruct

Converts a datetime value into a variable of MqlDateTime structure type

StructToTime

Converts a variable of MqlDateTime structure type into a datetime value

Day

Returns the current day of the month, i.e., the day of month of the last known server time

DayOfWeek

Returns the current zero-based day of the week of the last known server time

DayOfYear

Returns the current day of the year i.e., the day of year of the last known server time

Hour

Returns the hour of the last known server time by the moment of the program start

Minute

Returns the current minute of the last known server time by the moment of the program start

Month

Returns the current month as number, i.e., the number of month of the last known server time

Seconds

Returns 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

TimeDay

Returns the day of month of the specified date

TimeDayOfWeek

Returns the zero-based day of week of the specified date

TimeDayOfYear

Returns the day of year of the specified date

TimeHour

Returns the hour of the specified time

TimeMinute

Returns the minute of the specified time

TimeMonth

Returns the month number of the specified time

TimeSeconds

Returns the amount of seconds elapsed from the beginning of the minute of the specified time

TimeYear

Returns year of the specified date

Year

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