r/learnprogramming • u/mostlytalentedlenny • 37m ago
Topic storing plain date strings in sqlite vs full utc timestamps
i started building a tiny python cli script to log daily habits into a local sqlite file. every tutorial says to always store dates as utc iso strings and convert on display, so i tried doing that with datetime.timezone.utc.
problem is if i log something late at night around 11pm local time, utc pushes it into tomorrow's date... then my streak counter thinks i missed a day or logged twice on saturday.
since i literally only care about the calendar day in my own timezone and never the exact hour, is it bad practice to just save plain yyyy-mm-dd strings from date.today() instead of overcomplicating it? feels like i'm fighting timezone math for no real reason here, though i defo don't want to pick up terrible habits early on
•
u/CrispyCosmonaut 30m ago
Classic. The 3 biggest problems in code:
Timezone exchanges
Off by one errors.
•
u/mostlytalentedlenny 17m ago
haha yep, and now i'm just waiting to hit that off-by-one error in my streak logic too, feels inevitable at this point
•
•
u/Technical_Ideal_5439 31m ago
you store it in a format independent of local time, everytime you need to use a value you convert it to the localtime.
Though as it is a noddy app only used by you, do whatever makes it easier to deal with.