0

Suppose I have the following student table:

id | name | datecreated
------------------------
1  | john | 5/28/2011
2  | peter| 3/15/2011
3  | luke | 5/19/2011

What would be my Sql statement if I want to select all students created in the month of May and in the year of 2011, regardless of date.

I am using SQLite.

3 Answers 3

1
SELECT * FROM tablename WHERE strftime('%Y', datecreated) = '2011' 
                          AND strftime('%m', datecreated) = '5';

Above example taken from: http://www.sqlite.org/lang_datefunc.html

Sign up to request clarification or add additional context in comments.

Comments

0

I think you need to use strftime('%Y','yourdatefieldvalue')

This should give you the year part and it takes only string as parameter for the DateTime value (Can't test the query as of now)

Comments

0

Try this

     select * from tablename where (datecreated < date('6/1/2011') and 
datecreated >= date('5/1/2011'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.