double ServerGmtOffsetHours=(TimeCurrent()-TimeGMT())/3600;
double ServerGmtOffsetHours=(TimeCurrent()-TimeGMT() +1800 )/3600;Round it to the nearest hour. (Won't work in fractional timezones like India.)
Round it to the nearest hour. (Won't work in fractional timezones like India.)
I figured out i could do it like this, but can someone else test this if it should be working in all Timezones.
int GetTimeZone() { int in_ho=TimeHour(TimeCurrent()); int st[4]; int GMT = TimeHour(TimeGMT()) & 0xFFFF; int res = in_ho - GMT; if(res<0){in_ho+=24;} return(in_ho-GMT); }
This will return the GMT Offset, it does that correctly on my PC using MetaQuotes-Demo, but i wanna be sure if it will be cool in all timezones...
Definitely it is not! You forget to consider that your pc clock might be wrong by a couple of minutes and that TimeCurrent() due to the latency caused by the internet is always a bit behind the correct time!
The int-cast - if I am right - always returns the lowest integer number not the nearest! WHRoeder's solution covers all that and its a lot simpler!
If you need India's fractions and you are sure the worst inaccuracy of both clocks is less than 7 minutes you can change his formula to :
double ServerGmtOffsetHours=(TimeCurrent()-TimeGMT() + 900 )/1800;
Definitely it is not! You forget to consider that your pc clock might be wrong by a couple of minutes and that TimeCurrent() due to the latency caused by the internet is always a bit behind the correct time!
The int-cast - if I am right - always returns the lowest integer number not the nearest! WHRoeder's solution covers all that and its a lot simpler!
If you need India's fractions and you are sure the worst inaccuracy of both clocks is less than 7 minutes you can change his formula to :

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I want to get GMT offset automatically in my expert, i tried using this code but i ain't sure its working like it should be...
I don't think this is correct, please how do i get the correct GMT offset?