Convert any datetime to UTC - MQL5

 

Hi, 


Is it possible to convert any date on a specific zone to UTC?


For example if I have 10/10/2021 in the 'Europe/London' zone, how could change it to UTC (taking into account the daylight saving)?


In javascript there is momentjs library, but I don't know how to do it in MQL5


Thanks

 

Chart times are broker times.

How can MetaQuotes know all brokers' (they come and go daily) Time zone and Daylight savings time (if they use it and including historical changes for back testing)? Do you have that information for just you and your broker? Only then, with code can you convert session times to broker's time to UTC to local time. You can use offset inputs but then you must maintain them correctly, through all three DST changes when they occur.
          When is the time zone problem going to be fixed? - General - MQL5 programming forum (2020.05.07)

You asked for  “any date.” Not possible unless you know your exact broker's TZ.

To convert current broker to local or back, see Time[5] in Local Time? - MQL4 programming forum #1 (2020.12.16) Substitute TimeGMT for local.

 

Thank you for you response. I don't want change the broker MT4 timezone.


I need convert a date from a timezone to UTC.


Thank you.

 
israelhernando #: I don't want change the broker MT4 timezone.


I need convert a date from a timezone to UTC.

  1. You can't change your broker's settings.
  2. Asked and answered.
 

Helo again, 


you are not understanding what i need. I don't want to change the time of the broker


I want to convert a date, on a datetime variable, in a specific time zone, to another time zone


Something like this:

var m = moment.tz("2013-11-18 11:55", "America/Toronto");

m.tz("Europe/Berlin").format(); // 2013-11-18T06:00:00+01:00


is it clear now?

Thank you

 
israelhernando #:

Helo again, 


you are not understanding what i need. I don't want to change the time of the broker


I want to convert a date, on a datetime variable, in a specific time zone, to another time zone


Something like this:


is it clear now?

Thank you

There's no function to retrieve the broker's timezone, so your indicator/EA will have to have a parameter to adjust this for each broker,
then is just a matter of summing the difference in seconds for the hour/minutes shift you need because the datetime type is just an
integer number representing the seconds elapsed since 1970-01-01 00:00.
 
 
Alexandre Borela #:
There's no function to retrieve the broker's timezone, so your indicator/EA will have to have a parameter to adjust this for each broker,
then is just a matter of summing the difference in seconds for the hour/minutes shift you need because the datetime type is just an
integer number representing the seconds elapsed since 1970-01-01 00:00.
ok, knowing the broker timezone, I could add the difference, but the difference changes in winter and summer time. then I need calculate if the date is in summer or winter time.

I need to download the transaction history from the broker and convert the dates to GMT. Depending on whether the transaction is in a winter or summer period, I will have to add/subtract more or less hours.

I thought there was some automatic way to do it.

Thanks
 
Carl Schreiber #:

Maybe you'll find your answers here:

https://www.mql5.com/en/articles/9926
https://www.mql5.com/en/articles/9929

interesting, thanks
Reason: