Integer and Date Time

 

Hello, 


I have this code to get the GMT in second, it give warning that I convert from datatime to int, yes, I know that. How to get rid of the warning? Can someone please help?


int GetGMTinSec () {
        return (TimeTradeServer()-TimeGMT());
}
 
Ching Soon Lim: Hello, I have this code to get the GMT in second, it give warning that I convert from datatime to int, yes, I know that. How to get rid of the warning? Can someone please help?

Make an explicit typecast. However, please note that a "datetime" is equivalent to a "long" and not an "int".

So, only use "int" for a time difference and not an actual full date and time, or else you will suffer information loss.

int GetGMTinSec( void ) {
   return int( TimeTradeServer() - TimeGMT() );
};
Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Typecasting - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Ching Soon Lim:

Hello, 


I have this code to get the GMT in second, it give warning that I convert from datatime to int, yes, I know that. How to get rid of the warning? Can someone please help?


Please note this code doesn't give you the "GMT in seconds". It gives you the broker server GMT time shift in seconds.

 
Fernando Carreiro #:

Make an explicit typecast. However, please note that a "datetime" is equivalent to a "long" and not an "int".

So, only use "int" for a time difference and not an actual full date and time, or else you will suffer information loss.

Thank you, this is what i need.

Reason: