Datetime to Int

 

Hi,

I need to convert the value of Time[] from datetime to an int variable.

Exist a quick way to transform an datetime variable into a int variable in Metatrader 4?

If is not possible, at least into double could serve either?

Very Thanks for your Help!! 

:) 

 
PabloLecce: I need to convert the value of Time[] from datetime to an int variable. Exist a quick way to transform an datetime variable into a int variable in Metatrader 4? If is not possible, at least into double could serve either?

It is called TypeCasting (follow the link for detailed information).

// ... for dates earlier then cerca 2100, it is safe to use "int" ...

int TimeInSeconds = (int) Time[0];

// ... or ...

int TimeInSeconds = int( Time[0] );

// ... a "datetime" actually occupies 8 bytes (in MQL4+/5), so should really be typecast into a "long" ...
// ... it is only safe to use "int" for dates up to D'2038.01.19 03:14:07' (int value of 2147483647) ...
// ... so you should use "long" to be on the safe side ...

long TimeInSeconds = (long) Time[0];
Typecasting - Data Types - Language Basics - MQL4 Reference
Typecasting - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Often a necessity occurs to convert one numeric type into another. Not all numeric types can be converted into another. Here is the scheme of allowed casting: Solid lines with arrows indicate changes that are performed almost without any loss of information. Instead of the char type, the bool type can be used (both take 1 byte of memory...
Reason: