Skip to content

Instantly share code, notes, and snippets.

@sri
Last active December 22, 2019 06:24
Show Gist options
  • Save sri/05e92bed217ed6fd2edb09dab63a4392 to your computer and use it in GitHub Desktop.
Save sri/05e92bed217ed6fd2edb09dab63a4392 to your computer and use it in GitHub Desktop.
Sqlite convert datetime
-- Convert m/d/yyyy to yyyy-mm-dd -- Sqlite recognize this format
-- See https://fivethirtyeight.datasettes.com/fivethirtyeight?sql=select+%0D%0A++--+year%0D%0A++substr%28substr%28date_game%2C+instr%28date_game%2C+%27%2F%27%29%2B1%29%2C+instr%28substr%28date_game%2C+instr%28date_game%2C+%27%2F%27%29%2B1%29%2C+%27%2F%27%29%2B1%29%0D%0A++++%7C%7C+%22-%22+%7C%7C%0D%0A++--+month%0D%0A++substr%28date_game%2C+0%2C+instr%28date_game%2C+%27%2F%27%29%29%0D%0A++++%7C%7C+%22-%22+%7C%7C%0D%0A++--+day%0D%0A++substr%28date_game%2C+instr%28date_game%2C+%27%2F%27%29%2B1%2C+instr%28substr%28date_game%2C+instr%28date_game%2C+%27%2F%27%29%2B1%29%2C+%27%2F%27%29-1%29%0D%0A++as+played_on%2C+%0D%0A++*+from+%5Bnba-elo%2Fnbaallelo%5D+%0D%0Awhere+played_on+%3E%3D+%272000-01-01%27%0D%0A
select
-- year
substr(substr(date_game, instr(date_game, '/')+1), instr(substr(date_game, instr(date_game, '/')+1), '/')+1)
|| "-" ||
-- month
substr(date_game, 0, instr(date_game, '/'))
|| "-" ||
-- day
substr(date_game, instr(date_game, '/')+1, instr(substr(date_game, instr(date_game, '/')+1), '/')-1)
as played_on,
* from [nba-elo/nbaallelo]
where played_on >= '2000-01-01'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment