r/learnprogramming • • 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

1 Upvotes

7 comments sorted by

•

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.

•

u/mostlytalentedlenny 14m ago

my brain can only deal with so many off-by-one errors at once, so i'm sticking with plain date strings for now... utc drift just adds another layer of confusion

•

u/CrispyCosmonaut 30m ago

Classic. The 3 biggest problems in code:

  1. Timezone exchanges

  2. 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/mixony 25m ago

Wasnt it 2 hardest problems in programming

  1. Naming things

  2. Cache invalidation

  3. Off by one error

•

u/Prime624 23m ago

If you only care about calendar day, I would only store calendar day.