Download MetaTrader 5
To add comments, please log in or register
The Market has more than 400 indicators. Try any of them!
Yu Chao
8
Yu Chao 2015.12.15 03: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 

Keith Watford
Moderator
7908
Keith Watford 2015.12.15 03: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.
Ali Akcaagac
169
Ali Akcaagac 2015.12.15 09: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);

...

/
To add comments, please log in or register