how to change mql4 time format?

 

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 

 
  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.
 

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);

...

Reason: