True. I just find integers easier to work with. Wanna span over a range? Just add some number to the start date. With ISO strings I now gotta worry about whether or not the end of the month was reached. Still okay to work with (because I can just convert to a date type in the program, do my calculations and then stringify again) but the numbers are more straightforward.
sqlite> SELECT datetime('now');
2023-04-29 03:54:59
sqlite> SELECT datetime('now', '+3 months');
2023-07-29 03:55:03
sqlite> CREATE TABLE foo(date TEXT NOT NULL);
sqlite> INSERT INTO foo (date) VALUES (datetime('now')), (datetime('now', '+3 months')), (datetime('now', '-3 months'));
sqlite> SELECT date FROM foo;
2023-04-29 03:55:33
2023-07-29 03:55:33
2023-01-29 03:55:33
sqlite> SELECT datetime(date, '+1 month') FROM foo;
2023-05-29 03:55:33
2023-08-29 03:55:33
2023-03-01 03:55:33
Personally, I still just use integers anyway. Stores smaller, easier to reason about, and usually it's easier to work with timestamps to convert between the database and the language's preferred datetime representation.
62
u/maxinstuff Apr 29 '23
If you use ISO compliant datetime strings they’ll sort correctly as strings too 🤓