chaitanya
chaitanya

Reputation: 1601

Obtain all the players born in a particular month in Sqlite

I have a players table which contains the following attributes

_id INTEGER PRIMARY KEY, name text not null,birth_date date not null

I want a query which can give me a list of all the players born in a particular month say May of 1986.

How could this be achieved? I tried using the date and time functions provided in SQLite but they were of no use.

Any pointers would be appreciated.

Thanks

Upvotes: 0

Views: 187

Answers (3)

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115630

SELECT p.name
     , p.birth_date
FROM Player p
WHERE p.birth_date >= '1986-05-01'
  AND p.birth_date < date('1986-05-01','+1 month') 
;

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359986

SELECT p.name, p.birth_date
    FROM Player p
        WHERE p.birth_date > '1986-04-30'
            AND p.birth_date < '1986-06-01';

(untested)

Upvotes: 4

Joe Krill
Joe Krill

Reputation: 1733

I think this should work. I haven't tried it:

SELECT _id, name, birth_date 
FROM players 
WHERE strftime('%m',birth_date) = '05' AND  strftime('%Y',birth_date) = '1986'

Upvotes: 2

Related Questions