Skip to content

Instantly share code, notes, and snippets.

@innermond
Created August 6, 2024 10:30
Show Gist options
  • Save innermond/12205ab496d429fd755513896f66e79e to your computer and use it in GitHub Desktop.
Save innermond/12205ab496d429fd755513896f66e79e to your computer and use it in GitHub Desktop.
If you send a date time (without timezone specifier) to a SQLite database they will be saved as UTC (not as your local time). The following query corrects this issue.
--- localtime of sqlite MUST be the same with app that sent incorrect touched_date
with param as (
select
touched_date as v, timediff(datetime(touched_date, 'localtime'), datetime(touched_date)) as delta from <errored-table-name>)
select
delta,
datetime(v),
CASE WHEN SUBSTR(delta, 1, 1) = '+'
THEN datetime(v, REPLACE(delta, '+', '-'))
ELSE datetime(v, REPLACE(delta, '-', '+'))
END
from
param;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment