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

2 Upvotes

5 comments sorted by

•

u/Technical_Ideal_5439 11m 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/CrispyCosmonaut 11m ago

Classic. The 3 biggest problems in code:

  1. Timezone exchanges
  2. Off by one errors.

•

u/mixony 5m ago

Wasnt it 2 hardest problems in programming

  1. Naming things
  2. Cache invalidation
  3. Off by one error

•

u/Prime624 4m ago

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