Best Practices: Date conversion

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Best Practices: Date conversion

Post by OhioJoe »

Moving from DBF to SQL. When I did this before (to SQLite) I converted the DBF dates to strings:
09/10/2021 becomes "20210910"
The table column was an 8-space Char type. Easy to convert and fairly easy to adjust the programming logic throughout the app.
My question is:
Is this the way to do it going forward, or should I use another approach?
Trying to use a common date format that works across all SQL database types.
Thanks everyone.
Joe Curran
Ohio USA
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

Best Practices: Date conversion

Post by Jamal »

Joe,

I think it is better to use the ISO Date type for the SQL column. The syntax is: YYYY-MM-DD
VO 2.8 Sql Class Library has DToCSQL(dDate) to convert VO date to a SQL Date. You may also create your own functions to handle date and time values.
for example:

Code: Select all

 ? DToCSQL(Today())    // returns: 2021-09-10
Using SQL date columns will make it to sort and query the data using SQL statements.

Jamal
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Best Practices: Date conversion

Post by OhioJoe »

Thank you, Jamal
Joe Curran
Ohio USA
Post Reply