Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Precision in DateTime Arithmetic
Message
From
01/12/2012 12:33:01
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
30/11/2012 20:03:12
Al Doman (Online)
M3 Enterprises Inc.
North Vancouver, British Columbia, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Miscellaneous
Thread ID:
01558431
Message ID:
01558549
Views:
73
>>>Suppose you have 2 different datetime values t1 and t2.
>>>
>>>If you subtract them e.g. t2 - t1, you get the time difference in seconds. Actually it seems to be the FLOOR() of the difference i.e.
>>>
>>>- anything less than 1 second returns 0
>>>- anything less than 2 seconds, but greater to or equal to 1 second, returns 1
>>>- etc.
>>>
>>>My understanding is that as an 8-byte type, DateTime values are stored with considerable precision, of the order of about 10 milliseconds (?) Is there any way to calculate differences with more precision?
>>>
>>>I understand SECONDS() can be used to get more precision, but what I'm dealing with are DateTime values stored in tables.
>>
>>
>>If you look here: https://github.com/RickCHodgin/SaveToParser
>>
>>You'll find an app which can parse a VFP "SAVE TO file" memory dump. One of its abilities is to parse a datetime field. The source code is here:
>>https://github.com/RickCHodgin/SaveToParser/blob/master/SaveToParser/SaveToParser.cpp
>>
>>The code in C/C++ to extract the components of a datetime variable begin around line 492.
>>
>>You can see from the functions immediately below that code how it is extracted.
>>
>>It uses a 64-bit floating point format when stored to a disk file. If it is the same in VFP then you could convert it using similar code through a custom DLL, or clever use of the printf() functions.
>>
>>You could also create a VFP function which does a SAVE TO file.mem LIKE varname, and just save that one, parse it in the disk file, read in the disk file, and get your milliseconds value that way. Hacky, but the code is already there to make that work.
>
>Interesting approach - thanks. I think the main point is ( as Fabio points out ), DATETIME( ) does not return milliseconds by itself. If that's what was stored, the precision just isn't there.
>
>In my reply to him I explore a couple of ways to work with milliseconds.
>
>I did an early test combining yours and Luis' approaches. I hacked the .MEM file, changed the "T" variable type to "C" with the hope of parsing the result in VFP. However, doing a RESTORE FROM a .MEM file hacked like that crashes VFP :-[

Never been a fan of such hacking. I once saw a program where, in order to get a progress bar during indexing, a UDF call was added to the index on command and then the index file header was hacked to remove the call. I just never feel like we know what such hacks will trip.
Previous
Reply
Map
View

Click here to load this message in the networking platform