I’m working in SQLite so I’m storing dates as just text.
YYYY-MM-DD hh:mm:ss
As far as I can determine, I should be able to order them or compare them with each other just as they are not worrying about date functions since any incrementing starts right and moves left, just like numbers, and all the values are numeric, and the non-numeric characters are always standardized and I’m using 24-hour time.
I keep seeing people online mentioning how dates as text have to be converted for any comparisons, but I don’t see why they wouldn’t just work as-is so long as they’re in that greatest -> smallest order. Obviously I can’t do math, but Select DateTime From Table where DateTime > 2010-04-21 15:34:55 should be totally reliable, right?
Is there some exception I’m not thinking of?
The reason you’re seeing lots of mentions of conversion when storing dates in a database, is that most database engines have a ‘native’ data type for date/time. SQLite doesn’t. It suggests you store dates as string or as julian date floating-point values.
Also, some other databases have rather obscure date-to-string functions (I’m looking at you, SQL Server), where it’s hard to figure out how to get a sortable date string. SQLite’s default date format (YYYY-MM-DD HH:NN:SS) is perfectly sortable and easy to read.
You’ll do fine with text dates when comparing or collating — as long as you use the right format, like you’re presenting.
In fact, you can even do math, by using SQLite’s date and time functions; they’re rather unorthodox but surprisingly flexible.