Download MetaTrader 5

Wrong datetime computing?

To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
zifu wang
636
zifu wang 2013.12.07 17:42 

There are  376565 days between 1970.01.01 00:00:00 and 3000.12.31 23:59:59. so the number of seconds is 376565*24*60*60-1=32535215999.

but computing in MQL5,

   datetime AA=D'3000.12.31 23:59:59';
   printf(TimeToString(AA,TIME_DATE|TIME_SECONDS));
   printf("%u",AA);

The output result is:

2013.12.08 00:32:05.924    aaa (EURUSD,M5)    2470444927
2013.12.08 00:32:05.924    aaa (EURUSD,M5)    3000.12.31 23:59:59

Alain Verleyen
Moderator
30737
Alain Verleyen 2013.12.07 18:18  
kwang1:

There are  376565 days between 1970.01.01 00:00:00 and 3000.12.31 23:59:59. so the number of seconds is 376565*24*60*60-1=32535215999.

but computing in MQL5,

The output result is:

2013.12.08 00:32:05.924    aaa (EURUSD,M5)    2470444927
2013.12.08 00:32:05.924    aaa (EURUSD,M5)    3000.12.31 23:59:59

Why are you thinking datetime is an unsigned int ? Documentation said it's an 8 bytes value, so it's a long not an int.

   printf("As number of seconds %llu",AA);

Result:

2013.12.07 18:14:07    Test (EURUSD,H1)    As number of seconds 32535215999

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.07 18:28  
kwang1:

There are  376565 days between 1970.01.01 00:00:00 and 3000.12.31 23:59:59. so the number of seconds is 376565*24*60*60-1=32535215999.

but computing in MQL5,

The output result is:

2013.12.08 00:32:05.924    aaa (EURUSD,M5)    2470444927
2013.12.08 00:32:05.924    aaa (EURUSD,M5)    3000.12.31 23:59:59

Try . . . 

printf("%I64",AA);

 . . . for an unsigned long

Alain Verleyen
Moderator
30737
Alain Verleyen 2013.12.07 19:08  
RaptorUK:

Try . . . 

 . . . for an unsigned long

  • "%I64" isn't a valid format. See documentation.
  • I64 isn't specific to unsigned, it's available for signed also.
  • You have to use "%I64u" or "%llu" as I previously posted.
zifu wang
636
zifu wang 2013.12.08 02:38  
Thank you very much.....
To add comments, please log in or register