Todd Vance
Todd Vance

Reputation: 4711

Mysql results within a specific year on a datetime column

I am trying to get results back within year 'N' on a datetime column... I was hoping I could do something like this: DOD BETWEEN '2014-1-1' AND '2013-1-1' but I get nothing back with that.

Upvotes: 0

Views: 38

Answers (2)

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115560

So indexes can be used:

WHERE dod >= '2013-01-01'
  AND dod < '2014-01-01'

or:

WHERE dod >= MAKEDATE(2013, 1)   -- first day of the year
  AND dod < MAKEDATE(2014, 1)

Upvotes: 2

John Conde
John Conde

Reputation: 219844

Use YEAR()

WHERE YEAR(DOD) = 2013

Upvotes: 3

Related Questions