Please, always use the CODE button (Alt-S) when inserting code.
Hello you can maybe use this:
MqlDateTime
The date type structure contains eight fields of the int type:
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; // Day number of the year (January 1st is assigned the number value of zero) }; |
Note
The day number of the year day_of_year for the leap year, since March, will differ from a number of the corresponding day for a non-leap year.
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); }
|
See also

Char, Short, Int and Long Types - Integer Types - Data Types - Language Basics - MQL4 Reference
- docs.mql4.com
Char, Short, Int and Long Types - Integer Types - Data Types - Language Basics - MQL4 Reference
-
void OnStart(){ Print(GetTime()); // 24.5.2023 }
Works fine for me. You are doing something else.
credetarud: But somehow when this runs I get 0.1.1900 every time.Probably not connected to a broker.
- You want the leading zeros. Simplify, generalize.
string GetTime(datetime when=0) { if( when==0) when=TimeCurrent(); return StringFormat("%02d.%02d.%04d", TimeDay(when), TimeMonth(when), TimeYear(when) ); } void OnStart(){ Print(GetTime()); // 24.05.2023 }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I'm trying to use these functions. For example this one:
https://docs.mql4.com/dateandtime/day
But somehow when this runs I get 0.1.1900 every time. Not the real broker time. What am I doing wrong?
Thanks