Skip to content

Instantly share code, notes, and snippets.

@ks--ks
Last active July 6, 2020 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ks--ks/b64b10ce95065655431b5728d4e52aeb to your computer and use it in GitHub Desktop.
Save ks--ks/b64b10ce95065655431b5728d4e52aeb to your computer and use it in GitHub Desktop.
Data converting in sqlite
--convert `$150.00` to cents `15000` query sqlite>
select replace(replace(Amount, '$', ''), '.', '') from test limit 5;
-- convert `$150.00` to cents `15000` in integer so we can `sum` query sqlite>
select cast(replace(replace(Amount, '$', ''), '.', '') as integer)
from test
limit 5;
-- check column type sqlite>
select typeof(created_at)
from test
limit 5;
-- text convert `03-02-2017` to `2017-02-03` query `sqlite>
select created_at, date(substr(created_at,7,4)||'-'||substr(created_at,4,2)||'-'||substr(created_at,1,2))
from test
limit 5;
-- export query output to file and exit
.once output.txt
.exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment