Diference in days/hours/... between OrderCloseTime and OrderOpenTime

To add comments, please log in or register
Jose Luis Lominchar
747
Jose Luis Lominchar  

Hi,

could somebody tell me how to print the diference in days/hours/... between OrderCloseTime() and OrderOpenTime()?

Thanks

Keith Watford
Moderator
20371
Keith Watford  

There may be simpler ways.

  int time_length=(int)(OrderCloseTime()-OrderOpenTime());
  
  int seconds=time_length%60;
  time_length-=seconds;
  int minutes_seconds=time_length%3600;
  int minutes=minutes_seconds/60;
  time_length-=minutes_seconds;
  int hours_seconds=time_length%86400;
  int hours=hours_seconds/3600;
  time_length-=hours_seconds;
  int days=time_length/86400;
  Print("Difference is ",days," Days ",hours," Hours ",minutes," Minutes ",seconds," Seconds");
Jose Luis Lominchar
747
Jose Luis Lominchar  

Thanks, for days this seems to work:




TimeDay(OrderCloseTime() - OrderOpenTime());
Keith Watford
Moderator
20371
Keith Watford  
Jose Luis Lominchar:

Thanks, for days this seems to work:

TimeDay(OrderCloseTime() - OrderOpenTime());

Not if it was open for more than 31 days

Alain Verleyen
38674
Alain Verleyen  
Keith Watford:

Not if it was open for more than 31 days

If for less than 31 days, it's not correct.
Alain Verleyen
38674
Alain Verleyen  
Keith Watford:

There may be simpler ways.

   printf("Difference is %i Days %s", time_length/86400, TimeToString(time_length, TIME_MINUTES|TIME_SECONDS));

// OR

   MqlDateTime dt; TimeToStruct(time_length,dt);
   printf("Difference is %i Days %i Hours %i Minutes %i Seconds",time_length/86400,dt.hour,dt.min,dt.sec);

To add comments, please log in or register