Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Querying for items stored in UTC that were created on a Thursday in PST#
This came up as a question on Hacker News. How can you query a SQLite database for items that were created on a Thursday in PST, when the data is stored in UTC?
I have datetimes stored in UTC, so I first needed to convert them to PST by applying the 8 hour time difference, using datetime(author_date, '-8 hours') as author_date_pst.
Then I used strftime('%w') to get the day of week (as a number contained in a string).
Then I can filter for that equalling ‘4’ for Thursday.
1select2 author_date,3 datetime(author_date, '-8 hours') as author_date_pst,4 strftime('%w', datetime(author_date, '-8 hours')) as dayofweek_pst,5 *6from7 commits8where9 dayofweek_pst = '4' -- ThursdaySQLite documentation for date time functions is at https://sqlite.org/lang_datefunc.html
Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.