how to change mql4 time format?

Back to topics list To post a new topic, please log in or register
avatar
1
yc8775 2015.12.15 04:19
 

Hi there,

When I output datetime to a csv file, it shows    2015.12.10 20:58:39. 

 Is there any way I can change the format like   20151210205839  , which eliminate the dots and colons?

 Thanks 

avatar
Moderator
3407
GumRai 2015.12.15 04:49 #
 
  string now_date=TimeToStr(TimeCurrent());
  StringReplace(now_date,".","");
  StringReplace(now_date," ","");
  StringReplace(now_date,":","");
  Print(now_date);
I don't know if this is the most efficient way, but it will do it.
avatar
145
aakcaagac 2015.12.15 10:48 #
 

Another approach:

MqlDateTime n_struct;
datetime n_date = TimeCurrent();
TimeToStruct(n_date, n_struct);
printf("%04d%02d%2d%2d%2d%2d", n_struct.year, n_struct.mon, n_struct.day, n_struct.hour, n_struct.min, n_struct.sec);

...

Edit: Probably shorter approach (not tested):

MqlDateTime n_struct;
datetime n_date = TimeCurrent(n_struct);
printf("%04d%02d%2d%2d%2d%2d", n_struct.year, n_struct.mon, n_struct.day, n_struct.hour, n_struct.min, n_struct.sec);

...

Back to topics list  

To add comments, please log in or register