MQL4 - automated forex trading   /  

Forum

Date Question

Back to topics list To post a new topic, please log in or register

avatar
18
stockwet 2006.07.12 19:30 
I've done a search through the site and the documentation, but can't find any information on how to concatenate date parts. What I'd like to do is to create a dynamic magic number based on today's date, formated as 20060712. The closest I've come is using the StrToTime function:

string var1=TimeToStr(CurTime(),TIME_DATE);

This gets me 2006.07.12, but, I don't want the periods in there because the magic number would choke.

Does anyone have suggestions? If I can't get the formatting needed, is it possible to use a CurDate() value for the magic number in an order?

Thanks.
Easy Way to Publish a Video at MQL4.Community

Easy Way to Publish a Video at MQL4.Community

It is usually easier to show, than to explain. We offer a simple and free way to create a video clip using CamStudio for publishing it in MQL.community forums.


avatar
Moderator
2824
Tatyana 2006.07.13 16:28 
Yes, you can use the CurTime() function or the LocalTime() function to create the dynamic magic number.

avatar
18
stockwet 2006.07.13 19:54 
Thanks. But, I can't format it the way that I want, correct?

avatar
Moderator
2824
Tatyana 2006.07.14 11:10 

You can try to use this code:

extern int My_magic_number, myYear, myMonth, myDay;

int start()
{
// we would like to get the date formatted as 20060714
// year = 20060000 = 2006*10000
// month= 0700 = 7*100
// day = 14

myYear = TimeYear(CurTime()) * 10000;
myMonth = TimeMonth(CurTime()) * 100;
myDay = TimeDay(CurTime());

My_magic_number = myYear + myMonth + myDay;

Print("My_magic_number = ", My_magic_number);

return(0);
}

Back to topics list  

To add comments, please log in or register