Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BUG: int() returning wrong values from datetime operatio
Message
From
02/11/2005 11:48:33
 
 
To
02/11/2005 10:57:40
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2000 Server
Miscellaneous
Thread ID:
01058678
Message ID:
01064526
Views:
48
After some experimenting it seems SECONDS() is also not completely reliable, somehow it gets out of sync with the datetime() value...
So we better use the winapi to get the systemtime (see below)

>function DateTimeExt
>* extend datetime() with millisecond reso
>LOCAL ltNow,lnSeconds
>ltNow=DATETIME()
>lnSeconds=SECONDS()
>* check if we didnt get an timeupdate during the 'store'
>DO WHILE SEC(ltNow)<>INT(MOD(lnSeconds,60))
> ltNow=DATETIME()
> lnSeconds=SECONDS()
>ENDDO
>RETURN DTOT(TTOD(ltNow))+lnSeconds

New version:
function DateTimeExt
DECLARE GetLocalTime IN kernel32 STRING @ lpSystemTime
LOCAL lcTimeBuffer,ltNow
lcTimeBuffer = REPLI (Chr(0), 16) && SYSTEMTIME structure
= GetLocalTime (@lcTimeBuffer)
ltNow=DATETIME(buf2word (SUBSTR(lcTimeBuffer, 1, 2)),;
buf2word (SUBSTR(lcTimeBuffer, 3, 2)),;
buf2word (SUBSTR(lcTimeBuffer, 7, 2)),;
buf2word (SUBSTR(lcTimeBuffer, 9, 2)),;
buf2word (SUBSTR(lcTimeBuffer, 11, 2)),;
buf2word (SUBSTR(lcTimeBuffer, 13, 2))) ;
+ buf2word (SUBSTR(lcTimeBuffer, 15, 2))/1000
RETURN ltNow

FUNCTION buf2word (lcBuffer)
RETURN;
Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256
ENDFUNC

* if you have VFP9 you can replace the buf2word call with ctobin(substr(..),'2RS')
Previous
Reply
Map
View

Click here to load this message in the networking platform