Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time span in days (int)
#1
Let me first wish a Happy and Prosperous New Year to all QM-users.

I wonder whether there exists a fast way to calculate the time span (in days, int) between two dates stored in integer variables in the form yymmdd. I understand that you may convert the int values to strings in the form dd/mm/yyyy, then assign them to DATE variables and finally calculate their difference. My question is whether there exists a simple way to do it and i miss it.

Many thanks in advance.
#2
Quote:I wonder whether there exists a fast way
No.
One of ways:
Macro Macro2766
Code:
Copy      Help
int d1=(16<<16) | (1<<8) | 3 ;;date 16-01-03 -> 0x100103
int d2=d1+5 ;;+ 5 days

int spanDays
TimeSpanGetParts sub.DateIntToDateTime(d2)-sub.DateIntToDateTime(d1) spanDays
out spanDays


#sub DateIntToDateTime
function'DateTime dateInt

;note: year must be 2-digit, assuming that the actual year is 2000-2099.


DateTime r.FromParts(dateInt>>16&255+2000 dateInt>>8&255 dateInt&255)
ret r
#3
Dear Gintaras, Many thanks indeed!

Supposed that date is initially stored in an int dr=160103 could you please suggest a fast way to convert it in the d1 form in your example?
#4
Supposed that date is initially stored in an int dr=160103 could you please suggest a fast way to convert it in the d1 form in your example?
#5
Macro Macro2770
Code:
Copy      Help
int spanDays
TimeSpanGetParts sub.DateIntToDateTime(160205)-sub.DateIntToDateTime(160103) spanDays
out spanDays


#sub DateIntToDateTime
function'DateTime dateInt

;dateInt - date in decimal format, like 160103 (2016-01-03)

;note: year must be 2-digit, assuming that the actual year is 2000-2099.


DateTime r.FromParts(dateInt/10000%100+2000 dateInt/100%100 dateInt%100)
ret r


Forum Jump:


Users browsing this thread: 3 Guest(s)