Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A Datetime problem
Message
De
19/12/1999 09:32:13
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
18/12/1999 22:36:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00305771
Message ID:
00305853
Vues:
31
>I have a problem with a datetime calculation. I am running VFP6.0 (No SP3 yet) I run the following:
>
>create cursor test (START_DT T, END_DT T, CALC_SEC I)
>ltStart = {^1999-12-05 08:00}
>ltEnd = {^1999-12-05 18:00}
>insert into test (START_DT, END_DT, CALC_SEC) VALUES ;
> (ltStart, ltEnd, ltEnd -ltStart)
>? ltEnd - ltStart
>? CALC_SEC
>
>I get a responce of:
>
>36000
>35999
>
>Whats the difference between storing the value in a field or just printing it? Ok, 1 seconds not that big of a deal but I spent a few hours trying to figure out why my calculations were off. Do other versions of VFP have this same problem?
>
>-David-


David,
Unlike dates, datetime is stored as a double. I hit this sometime ago too and discussed here. If hour portion is not a multiple of 3 then roundation problems occur.
insert into test (START_DT, END_DT, CALC_SEC) VALUES ;
(ltStart, ltEnd, round(ltEnd -ltStart,0))
would have correct result.
While inserting you make Calc_Sec an integer causing it to get integer part which is 35999. If you :
? (ltEnd - ltStart) * 1.00000
You would see the calculation in fact returns something like 35999.99997.
It doesn't make sense tome too :)
PS: If it's a join expression in a SQL then use ttoc(tDateTime,1) instead.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform