Alternative to STR_TO_DATE () in sqlite

What is the alternative in SQLite as STR_TO_DATE()funciton in MySQL?

+3
source share
2 answers

I know that this post is a little outdated, but I am sending anyway those who may have the same problem as mine. I got the date from the open api as "2013-01-01T01: 00: 00 + 0000" and saved it as a string in sqlite. The problem arose when I needed a way to query records based on a date range. Since I could not use STR_TO_DATE (), I found that I could use the sqlite strftime () function. Below is an example of a work request that I use for this instance, hope it can help someone else:

 select strftime(date_created) as dateCreated from tblFeeds 
 where strftime(date_created) between strftime('2013-01-01') and strftime('2013-01-08')
 order by dateCreated;

, 01-01-2013 01-08-2013 (7 ).

, , :

( 24 ):

select strftime(date_created) as dateCreated from tblFeeds 
where strftime(date_created) between  strftime(date('now','-24hours')) and  strftime(date('now'))
order by dateCreated

( ):

select strftime(date_created) as dateCreated from tblFeeds 
where strftime(date_created) between  strftime(date('now','-7days')) and  strftime(date('now'))
order by dateCreated

( ):

select strftime(date_created) as dateCreated from tblFeeds 
where strftime(date_created) between  strftime(date('now','-1months')) and  strftime(date('now'))
order by dateCreated
+2

Source: https://habr.com/ru/post/1724907/


All Articles