Download MetaTrader 5
To add comments, please log in or register
Share links from other resources. Now they have a description.
kay
44
kay 2013.10.10 22:47 

hi guys.

i'm studying as noob.

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

GreenMoney
379
GreenMoney 2013.10.10 23:13  

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
Tjipke de Vries
6298
Tjipke de Vries 2013.10.10 23:25  
string Date = TimeToStr(TimeCurrent(),TIME_DATE);//"yyyy.mm.dd"
kay
44
kay 2013.10.11 02:25  
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
kay
44
kay 2013.10.11 02:25  
deVries:


thx was helpful
parham.trader
193
parham.trader 2013.11.01 09:39  
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 .

whroeder1
14243
whroeder1 2013.11.01 12:27  
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) );      }
Tonny Obare
1023
Tonny Obare 2013.11.01 14:42  
deVries:


Devries is right this is the quickest and simplest way.
john
213
john 2013.12.26 01:55  

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

com37
21
com37 2013.12.26 09:51  
deVries:



thx budy it works well
GreenMoney
379
GreenMoney 2013.12.26 14:48  
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)?
/ /12
To add comments, please log in or register