MqlDateTime Structure
Overview
The MqlDateTime structure is used to represent date and time values in MQL4. It contains eight integer fields.
Fields
year: Integer representing the year.mon: Integer representing the month (1-12).day: Integer representing the day of the month (1-31).hour: Integer representing the hour (0-23).min: Integer representing the minute (0-59).sec: Integer representing the second (0-59).day_of_week: Integer representing the day of the week. 0 for Sunday, 1 for Monday, ..., 6 for Saturday.day_of_year: Integer representing the day number of the year. January 1st is assigned the value 0.Constraints and Notes
day_of_year value may differ between leap years and non-leap years starting from March.Related Functions
TimeToStruct(): Converts a datetime value to an MqlDateTime structure.Example
void OnStart()
{
datetime date1 = D'2008.03.01';
datetime date2 = D'2009.03.01'; MqlDateTime str1, str2;
TimeToStruct(date1, str1);
TimeToStruct(date2, str2);
printf("%02d.%02d.%4d, day of year = %d", str1.day, str1.mon, str1.year, str1.day_of_year);
printf("%02d.%02d.%4d, day of year = %d", str2.day, str2.mon, str2.year, str2.day_of_year);
}
/* Result:
01.03.2008, day of year = 60
01.03.2009, day of year = 59
*/
Previous
arrow_back
Mql4 data structures