Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which Date Type in SQL Server?
Message
De
30/04/2018 08:24:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01659629
Message ID:
01659638
Vues:
68
>Hi,
>
>Still struggling through a VFP to SQL Server 2012 conversion. I have been using the Sedna Upsizing Wizard. VFP uses a DATE format of mmddyyyy and when I use the default 'datetime' it rejects invalid dates but brings over most of the records. Although it is stored on SQL as a datetime data type, it seems to display OK on my app. Has anyone had any experience as to which type should be used on a VFP app, datetime, datetime2 or date?
>
>TIA,
>
>Bill

Disclaimer: I haven't used any of the upsizers that come with VFP or added later, I coded my own upsizers (which also generate -write out- necessary CursorAdapter classes).

VFP (fox base and up) doesn't use a date format of mmddyyyy. In VFP a date is stored as character in yyyyMMdd format. mmddyyyy could be a custom format for display purposes only. When dealing with transfers to and from SQ server, you should use a date as a date (and not a character in mmddyyyy format). If you HAVE TO use character formats, the only reliable format for SQL Server is yyyyMMdd (for date) and yyyyMMdd HH:mm:ss (for date time). Simply use date as a date on VFP side and let the drivers do the necessary conversions for you. On SQL server side, you can use DateTime, DateTime2 or Date. Historically DateTime is the oldest and the only known one to VFP, thus you wouldn't see a conversion problem whichever SQL server drivers you use. If you use DateTime2 or Date with an old SQL server driver then the values might come in as character and produce unpredictable results. If you use latest SQL server drivers (or at least the one that is compatible with the database version you have) then you wouldn't see those problems (saying no problems, be aware that date times are stored as 8 bytes numeric values in SQL server and cannot exactly match what it shows - might show 2018 Oct 12 3:00:00 but there is milliseconds part which is not 0 for example. DateTime2 removes that problem).

To keep long story short, DateTime is easiest type to use for a VFP coder. If you get that into a "date" type column it would just work fine (either using CursorSchema with a CursorAdapter or appending into an existing cursor or altering data type later). In general you don't have to do anything special, in your forms you could simply format it as a date value.
Ç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