Formatting date and time

 

Hi,

I have an MQ4 indicator that formats date and time like this:

26.10.2023 - 09:11:45

using this code:

// This will take broker time and turn it into format DD.MM.YYY
string GetTime(datetime when=0)
{
   if( when==0) when=TimeCurrent();
   return StringFormat("%02d.%02d.%04d - %02d:%02d:%02d", TimeToString(TimeCurrent(),TIME, TimeMonth(when), TimeYear(when), TimeHour(when), TimeMinute(when), TimeSeconds(when) );
}

Improperly formatted code modified by moderator.

I've done some searching and can't find any example of how to do this using mq5. Can anyone assist?

Thank you!

 

Improperly formatted code modified by moderator. In the future, please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
credetarud: I have an MQ4 indicator that formats date and time like this: 26.10.2023 - 09:11:45. I've done some searching and can't find any example of how to do this using mq5. Can anyone assist?

Please study the MQL5 documentation for the following Time and Date function ...

TimeToStruct

Converts a datetime value into a variable of MqlDateTime structure type

Also study the following article ...

Articles

Migrating from MQL4 to MQL5

Sergey Pavlov, 2010.05.17 13:32

This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
Documentation on MQL5: Date and Time / TimeToStruct
Documentation on MQL5: Date and Time / TimeToStruct
  • www.mql5.com
TimeToStruct - Date and Time - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5