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

747

Hi,

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

Thanks

Moderator
20371

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");```
747

Thanks, for days this seems to work:

```

TimeDay(OrderCloseTime() - OrderOpenTime());```
Moderator
20371

Jose Luis Lominchar:

Thanks, for days this seems to work:

`TimeDay(OrderCloseTime() - OrderOpenTime());`

Not if it was open for more than 31 days

38674

Keith Watford:

Not if it was open for more than 31 days

If for less than 31 days, it's not correct.
38674

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);

```