简体   繁体   中英

SQlite compare dates without timestamp

In SQLite, how to compare date without passing timestamp?

The date format is 2018-03-18 08:24:46.101655+00 and I want to compare against only date part as 2018-03-18 .

I have tried as where mydate='2018-03-18' but that didn't return any records.

Similarly, tried Date(mydate)='2018-03-18' but that didn't help either.

How can I compare dates ignoring the timestamp part?

select * from mytable
where strftime('%Y-%m-%d', mydate) = '2018-03-18'

This is not one of the supported date formats .

To extract the date part from the string, use substr() :

... WHERE substr(mydate, 1, 10) = '2018-03-18'

It might be a better idea to store dates in a correct format in the database to begin with.

It is looking that there is problem with date format. Sqlite doesn't understand data like '+00' in date. So date() and strftime() will not work here if data type is 'timestamp with time zone'. Try by using like clause.

Try using strftime

SELECT strftime('%Y %m %d', 'columnName');

you can find it here strftime.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM