Brad wrote:

I am looking for a simple way of using date and time values with
sqlite3. I have some Ctime classes (VC++.net) which have to be stored in
the database and they should be compared.


If the class you're using has .Value property, or a way to easily transform the date from one format to another, you should probably store that. For instance, I like to store dates in string format, using something like "CCYYMMDDHHmmSS.SSSSSS". If I expect to need to deal with time zones, I'll store all the dates/times as GMT, or Universal time, and do the conversions when I create the datetime objects.


Storing as strings is great as long as you only ever display the values. Doing range checks on a stringified format becomes prohibitive, at best. If you're going to have to filter/query on the dates, by far your best bet is a simple number that is an offset from an epoch. Classic UNIX calendar time is effective for dates in the proper range for precisions above one second (most of us) or you can do something similar to Java's date representation that measures milliseconds since the epoch.

 -P

Reply via email to