Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper syntax for universal date
Message
De
10/04/2003 09:06:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/04/2003 01:44:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00775886
Message ID:
00775988
Vues:
13
>In VFP, on native VFP table, I can do:
>
>
>SELECT News.Numero FROM News;
> WHERE News.AddDate>={^2003/04/01 00:00:00} AND News.AddDate<={^2003/04/30 23:59:59};
> ORDER BY 2 ASC
>
>
>This doesn't work in SQLExec(). How can I have a universal format which would fit both? Or, how can I adjust it in order to have another syntax which would work for SQL Server?

Michel,
ODBC uses ODBC 'canonical format' for date&datetime. You could pass dtoc(dDateOrtDatetime,1). ie:

ldStart = {^2003/04/01}
ldEnd = {^2003/04/30} + 1 && Dealing with date part only - midnight

trans(dtoc(ldStart,1)'@R 9999/99/99 99:99:99')
trans(dtoc(ldEnd,1)'@R 9999/99/99 99:99:99')

And SQL server also recognizes directly dtoc(,1) result as a date/time (YYYYMMDD and YYYYMMDDhhmmss).

However with stringifying (a new word:) still you need to make sure you handle date or datetime format where time part is sensitive. Why don't you simply pass date or datetime parameters to your function. You could use that in both VFP and SQL server backends and don't bother with date/time settings at all. ie:

ldStart = {^2003/04/01}
ldEnd = {^2003/04/30 23:59:59}

lcSQL = 'select * from News where AddDate between ?ldStart and ?ldEnd'

&lcSQL && VFP
SQLExec(lnHandle,lcSQL) && SQL server

This works free from thinking you have date or datetime as field datatype or parameters datatype (handled implicitly converting a date to datetime pointing midnight).
PS: I know you don't want to pass parameters or a parameters object but why not :)
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