how to get today's date? in mql4?

 

hi guys.

i'm studying as noob.

plz help me how to get today's date? as "d=10" "m=10" y="2013"?

 

Day() returns the day of the month from the last known server time. Month() returns the month of the year from the last known server time. And Year() returns the current year from the last known server time.

Based on those functions, you can create today's date by:

datetime Today = StrToTime(StringConcatenate(Year(), ".", Month(), ".", Day()));

or you can calculate today by:

datetime Today = TimeCurrent() - (TimeCurrent() % (PERIOD_D1 * 60));  // Today at midnight
 
string Date = TimeToStr(TimeCurrent(),TIME_DATE);//"yyyy.mm.dd"
 
Thirteen:

Day() returns the day of the month from the last known server time. Month() returns the month of the year from the last known server time. And Year() returns the current year from the last known server time.

Based on those functions, you can create today's date by:

or you can calculate today by:


thx buddy solved
 
deVries:


thx was helpful
 
Thirteen:

Day() returns the day of the month from the last known server time. Month() returns the month of the year from the last known server time. And Year() returns the current year from the last known server time.

Based on those functions, you can create today's date by:

or you can calculate today by:

With Lotssss of thank for your helpful comment .

 
kayny: help me how to get today's date? as "d=10" "m=10" y="2013"?

And if you just want today's date (not parts)
#define HR2400 86400       // 24 * 3600
int      TimeOfDay(datetime when){  return( when % HR2400          );         }
datetime DateOfDay(datetime when){  return( when - TimeOfDay(when) );         }
datetime Today(){                   return(DateOfDay( TimeCurrent() ));       }
datetime Tomorrow(){                return(Today() + HR2400);                 }
datetime Yesterday(){               return( iTime(NULL, PERIOD_D1, 1) );      }
 
deVries:


Devries is right this is the quickest and simplest way.
 

Actually none of these answers are what he asked for. Though they are what he wanted.

He asked for Today's Date. Today's date is ONE date, today.

All of the above answers produce a historical date in reference to each sequential historical bar being evaluated.

My question is more specifically what he asked for originally, which is: how do we get Today's Date only?

By this I mean the date of this post, and no previous historical dates.

Last Bar on Chart Date. In the Tester, it treats each bar as the last bar, until it advances to the next bar, but in reality there is only ONE last bar on the chart.


Some calculations could be performed on the entire sample, only after the entire data set has been processed (once the last bar on the chart is reached).

Once the last bar is reached, and the EA is actually running live, then recalculating on each bar would not be too large a processing burden. (It would have the whole time bar period in which to calculate) Recalculating on each bar during a back test though puts a large time and processing burden on the testing, making it impractical.


Thanks

 
deVries:



thx budy it works well
 
moneycode:

. . .

All of the above answers produce a historical date in reference to each sequential historical bar being evaluated.

. . .

I don't think that is a correct statement. (Remember: TimeCurrent() returns "the last known server time (time of incoming of the latest quote) . . ..")

moneycode:

. . .

My question is more specifically what he asked for originally, which is: how do we get Today's Date only?

By this I mean the date of this post, and no previous historical dates.

. . .

How is your question any different from that of the OP? The responses given to the OP also answer your question: one can calculate today's date in MQL (using various methods, including those demonstrated above). Alternatively, you can make a call to the operating system to query the local date/time. However, how is that much different than TimeLocal() (the main difference being time returned in TimeLocal() is modelled in the strategy tester)?