Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Datetime gotcha
Message
De
29/11/1999 11:40:04
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Datetime gotcha
Divers
Thread ID:
00296388
Message ID:
00296388
Vues:
55
What I got as a lesson is that a datetime() which seem to be the same in two different tables might be different in fact.
ie: {01/16/1997 04:30:00 PM} might not be equal to {01/16/1997 04:30:00 PM}
Surprised anyone ? :) In my case fields were named "tdt".

? table1.tdt = table2.tdt && Returns .t. for a particular record - ohh well it should
But :

select * from t1 join t2 on t1.tdt = t2.tdt && Surprise - no match :)

The difference between 2 tables :
Table1 was generated from date starting from {01/16/1997} and start hour 16.30 (they entered time portion as N,5,2) at 1 hour intervals (811 records).

Table2 was generated from date starting from {01/16/1997} and start hour 16.00 (they entered time portion as N,5,2) at 1 hour intervals (811 records).

My coworkers told me that it was a wrong entry and table2 should have 30 mins shift to match the other. I said proudly "no problem, VFP knows datetime math very well :)" and wrote this code thinking that they would request this many times (in real use only start was kept in another info file) :
lparameters tc2File, tnShift
if type("tnShift") # "N"
  tnShift = 0
endif
lcFrom1 = getfile("DBF","Info dosyasi ?")
lcFrom2 = getfile("DBF","Velocity dosyasi ?")
select ;
	dtot(a.date_b) + ;
		int(a.tb)*3600 + ;
		((a.tb - int(a.tb)) * 100 * 60 ) ;
		AS tDT, ;
	B.Vel ;
	from (lcFrom1) a, (lcFrom2) b ;
	where  a.cm_code = b.cm_CODE ;
	into table (tc2File)
replace all tdt with ( tdt+(recno()-1)*3600 ) + tnShift
Run the code and browsed the tables proudly again showing them all data now had tnShift mins shift and could be joined easily. I forgot one little point. VFP stores datetime as real values not as YYYYMMDD... as in date type :( When I did the SQL (which I thought a child could do too) I got 0 records !

Only moving "+ tnShift" into SQL corrected the problem (before "as tdt").
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform