Download MetaTrader 5

Convert to Date and Time

To add comments, please log in or register
Winsor Hoang
4933
Winsor Hoang  

Hi,

 Please help me with a script that will convert the following MT4 date to regular date i.e. day/month/year

 

start_date=1388534400
end_date=1415059200


many thanks
honest_knave
Moderator
2433
honest_knave  

If you're happy to accept their format, take a look at TimeToString().

Otherwise, take a look at the MqlDateTime structure and TimeToStruct() which will give more flexibility on the output format.

Depends really on what you plan to do with the data, and the context of your question.

whroeder1
14785
whroeder1  
waterhorse: MT4 date to regular date i.e. day/month/year
  1. honest_knave: TimeToString().
  2. variations like
    string DDMMYYYY(datetime d){ // 01/01/2015
       return Stringformat("%02i/%02i/%i" TimeDay(d), TimeMonth(d), TimeYear(d) );
    }
    string DMYY(datetime d){   // 1/1/15
       return Stringformat("%i/%i/%02i" TimeDay(d), TimeMonth(d), TimeYear(d) % 100 );
    }
    :
    string c = StringFormat("From %s to %s", DDMMYYYY(start_date), DDMMYYYY(end_date));

Winsor Hoang
4933
Winsor Hoang  

Thanks got it!

To add comments, please log in or register