Someone please add a ".name" and a ".datetime" to MqlParam - page 2

 
Vladislav Boyko #:
Because the size of datetime is 8 bytes, and the size of int is 4 bytes. That is, not every datetime value will "fit" into the int type.

You can easily verify this:

datetime dt = TimeCurrent();
int _int = dt; // Compiler warning: possible loss of data due to type conversion from 'datetime' to 'int'
 
Vladislav Boyko #:
That is, not every datetime value will "fit" into the int type.

This is also easy to verify. Even an unsigned int cannot fit 900 years (almost 900) of the datetime range.

void OnStart()
  {
   long dtMax = D'31.12.3000';
   Print("dtMax = ", TimeToString(dtMax), ", UINT_MAX = ", TimeToString(UINT_MAX));
  }
2024.04.15 15:19:15.097 scriptTest (EURUSD,H1)  dtMax = 3000.12.31 00:00, UINT_MAX = 2106.02.07 06:28
 

By the way, if you want to print time using PrintFormat as an integer (number of seconds), then “%i” is not suitable for this:

void OnStart()
  {
   long dtMax = D'31.12.3000';
   PrintFormat("Wrong: %i, correct: %I64i", dtMax, dtMax);
  }
2024.04.15 15:36:25.371 scriptTest (EURUSD,H1)  Wrong: -1824608768, correct: 32535129600