Get datetime in epoch/timestamp

 
Hello,

I'm trying to get the opening time of a bar in timestamp/epoch. Time[0]

The only solution I'm finding on MQL4 site is not using the property #strict, which I'm not liking as a solution as it'll convert all datetime to timestamps. 

Is there a way to print the time of a bar in timestamp? 

Cheers,
Eashan
 
eashanm: I'm trying to get the opening time of a bar in timestamp/epoch. Time[0]. The only solution I'm finding on MQL4 site is not using the property #strict, which I'm not liking as a solution as it'll convert all datetime to timestamps. Is there a way to print the time of a bar in timestamp?

Please explain in more detail and with sample code.

Time[0] is already a "datetime" data-type which is equivalent to the Unix timestamp in seconds. No conversion is necessary.

Datetime Type

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory.

Constants of the date and time can be represented as a literal string, which consists of 6 parts showing the numerical value of the year, month, day (or day, month, year), hours, minutes and seconds. The constant is enclosed in single quotation marks and starts with the D character.

Values range from 1 January, 1970 to 31 December, 3000. Either date (year , month, day) or time (hours, minutes, seconds), or all together can be omitted.

With literal date specification, it is desirable that you specify year, month and day. Otherwise the compiler returns a warning about an incomplete entry.  

 
Fernando Carreiro #:

Please explain in more detail and with sample code.

Time[0] is already a "datetime" data-type which is equivalent to the Unix timestamp in seconds. No conversion is necessary.

Datetime Type

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory.

Constants of the date and time can be represented as a literal string, which consists of 6 parts showing the numerical value of the year, month, day (or day, month, year), hours, minutes and seconds. The constant is enclosed in single quotation marks and starts with the D character.

Values range from 1 January, 1970 to 31 December, 3000. Either date (year , month, day) or time (hours, minutes, seconds), or all together can be omitted.

With literal date specification, it is desirable that you specify year, month and day. Otherwise the compiler returns a warning about an incomplete entry.  



Yes, it is datetime but when you try to print it, it gives the datetime in standard format (YY.MM.DD HH.MM.SS) not in timestamp. Check the screenshot


Here is the code if you need:   Alert(Time[6]);

Files:
DateTime.png  201 kb
 
eashanm #Yes, it is datetime but when you try to print it, it gives the datetime in standard format (YY.MM.DD HH.MM.SS) not in timestamp. Check the screenshot. Here is the code if you need:   Alert(Time[6]);
 Alert( (long) Time[6] ); // Typecast it into an integer type in order for it to print as a number instead of a date-time