Question

I need to determine that if a particular date is a Sunday, find the date for the following Sunday. I am using strftime function below to check the day of the week, but my case statement does not evaluate properly. For example 2014-03-09 (ISO format) is a Sunday. I would have expected the following SQLite case statement to evaluate to 7.

select strftime('%w', date('2014-03-09'))  
, case when strftime('%w', date('2014-03-09')) = 0   then 7  else 0 end

generates

0|0    <-- Why isn't this 0|7?

What am I missing?

My version of SQLite is

SQLite 3.7.11 2012-03-20 11:35:50 00bb9c9ce4f465e6ac321ced2a9d0062dc364669
Was it helpful?

Solution

In your query, you're comparing a string to an integer, which will evaluate false. Try comparing it to a string:

case when strftime('%w', date('2014-03-09')) = '0'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top