Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug/Tricky feature of DateTime values
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Bug/Tricky feature of DateTime values
Miscellaneous
Thread ID:
00051516
Message ID:
00051516
Views:
69
Hi Folks,

Here is an issue that annoyed me for a while. This is revelant to anyone who wants to store a time span into a table and chooses to use an integer field to do it.

Try this

? {09/27/97 08:30am} - {09/27/97 08:00am}

The result is correctly displayed as 1800. This is the number of seconds between the two times.

Now try

? INT({09/27/97 08:30am} - {09/27/97 08:00am})

The result once again is 1800 secs.

Now try

CREATE TABLE Test (Timespan I)
APPEND BLANK
REPLACE timespan WITH {09/27/97 08:30am} - {09/27/97 08:00am}
BROWSE

Hmmm, the value stored in the field is 1799. It seems the value returned by the subtraction of two time fields is not an integer value and it gets truncated when storing in a integer field.

This can be seen by doing
? STR({09/27/97 08:30am} - {09/27/97 08:00am},20,10)

The result of this is 1799.9999731779

Now why INT() does not truncate this I'm not sure.

Hey I just tried something else. This is crazy!

INT(2.999999) = 2

but
INT(2.9999999999999999) = 3

Anyway, back to my point. If you ever want to store a timespan in an Integer field. Make sure you either use INT or ROUND(value,0) before storing it in the table!

Have fun!

Darrel
Next
Reply
Map
View

Click here to load this message in the networking platform