For example, if I have a modified_date field in table T, how do I select those with modified_date within most recent 5 days?
Is there other utility function to convert a datetime to a float number?
Thank you for your help!
Sqlite3: How to calculate the difference of two dates?
Started by Lance, Mar 06 2009 08:20 AM
8 replies to this topic
#1
Posted 06 March 2009 - 08:20 AM
|
|
|
#2
Posted 06 March 2009 - 08:28 AM
For most SQL databases, you would do something like:
SELECT * FROM T WHERE MODIFIED_DATE >= [five days ago]Usually, I do conversions within the language I'm using to access the database.
#3
Posted 06 March 2009 - 09:19 AM
Thanks Panther.
That's not exactly what I want. The thing is the date field is actually treated as a string. so '2009-3-15' will be greater than '2009-03-15', etc. I was wondering if there was a way to treated it as TIMESTAMP/DATETIME.
Is is because Sqlite3 doesn't have native datetime datatype support?
And yes, your proposal should work if I make sure datetime values always be formatted as yyyy-mm-dd hh:MM:ss before insert into a table.
That's not exactly what I want. The thing is the date field is actually treated as a string. so '2009-3-15' will be greater than '2009-03-15', etc. I was wondering if there was a way to treated it as TIMESTAMP/DATETIME.
Is is because Sqlite3 doesn't have native datetime datatype support?
And yes, your proposal should work if I make sure datetime values always be formatted as yyyy-mm-dd hh:MM:ss before insert into a table.
#4
Posted 06 March 2009 - 10:29 AM
I would approach it differently (having just done some reading). I would store DATETIMEs as floating point values, where the integer part is the number of days after a certain date, and the decimal part is the fraction of the day. Since many languages store datetime values with this approach anyway, I think it may be your best approach.
#5
Posted 06 March 2009 - 11:08 AM
Great idea!!
Should satisfy my needs. Thanks a lot!
Should satisfy my needs. Thanks a lot!
#6
Posted 06 March 2009 - 11:09 AM
I would have Rep+'d /Credit+'d you but I don't know how to :(
#7
Posted 06 March 2009 - 11:32 AM
Just use the little scale icon next to the #4(permalink)
#8
Posted 06 March 2009 - 12:10 PM
Done.
#9
Posted 06 March 2009 - 02:00 PM
or there is the unix method of storing time, an long integer with seconds since a certain time (1970-01-01 00:00:00). most programming languages has built-in support for converting this.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall


Sign In
Create Account


Back to top









