I'm saving im my table a colum current_date in this format: 'yyyy-MM-dd HH:mm'

How to search in database by date? I want, for examble the records from 2013-09-25 discarting the hour.

If I do this "Select current_date from mydatabase where current_date = '2013-09-25'" It does not work. I have to make this "Select current_date from mydatabase where current_date = '2013-09-25 09:25'". But i want only the record based on the date, not based on the date and hour.

有帮助吗?

解决方案

Apparently your dates are stored as Strings. You can use LIKE to discard the hour :

 select current_date from mydatabase where current_date like '2013-09-25%'

其他提示

SELECT * FROM mydatabase WHERE ( current_date > '2011-08-07') AND (current_date < '2011-08-08')

Replace the first date with the day you want information about and then update the second date with the following day.

You can directly use date function of sqlite

Select current_date from mydatabase where date(current_date) = '2013-09-25'

instead of

Select current_date from mydatabase where current_date = '2013-09-25'

Extra:- If you want to fetch using time then you can also do that using time function

Select current_date from mydatabase where time(current_date) = '09:25'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top