October 28, 2025, 05:00:07 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Calculate days between 2 dates using windows api

Started by zaphod, November 09, 2009, 07:43:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zaphod

I use filetime structure :
A FILETIME structure, implemented for 32-bit Windows, holds a 64-bit time value for a file.
This value represents the number of 100-nanosecond intervals since January 1, 1601.
'
I use a dialog with 2 datetimepicker :
date1 (first date), date2 (last date)


TYPE FILETIME
DEF dwLowDateTime AS INT
DEF dwHighDateTime AS INT
ENDTYPE
DECLARE IMPORT, SystemTimeToFileTime(lpSystemTime AS SYSTEMTIME,lpFileTime AS filetime),INT
'
SUB makelong(lo:INT,hi:int),int64
' thanx sapero
int64 value
pointer p = &value
*<int>p[0] = lo
*<uint>p[1] = hi
return value
ENDSUB
'
def std,stf:systemtime
stf=dtpGetSystemTime(d1, date2)
std=dtpGetSystemTime(d1, date1)
'
def t1,t2:int64
def t:double
def ft1,ft2:filetime
SystemTimeToFileTime(stf,ft1)
SystemTimeToFileTime(std,ft2)
'
t1=makelong(ft1.dwlowDateTime,ft1.dwHighDateTime)
t2=makelong(ft2.dwlowDateTime,ft2.dwHighDateTime)
'
t=(t1-t2)/864000000000q


The value of t is the number of days between dates.