Download MetaTrader 5

how to change mql4 time format?

To add comments, please log in or register
Yu Chao
8
Yu Chao  

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 

Keith Watford
Moderator
9996
Keith Watford  
  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.
Ali Akcaagac
168
Ali Akcaagac  

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

...

To add comments, please log in or register