user1854392
user1854392

Reputation: 91

How to put the first date of this year in a WHERE clause. MYSQL

I need my query to select all dates between the first date of this year and the present date. (ie all dates in database within this year), however my code does this but for the last 12 months. How can i alter my code to ensure its only dates from this year?

WHERE DATE_SUB(CURDATE(), INTERVAL 1 YEAR) <= date

Many Thanks

Upvotes: 1

Views: 873

Answers (2)

Andy Refuerzo
Andy Refuerzo

Reputation: 3332

where created_date between MAKEDATE(YEAR(now()), 1) and now();

MAKEDATE(YEAR(now()), 1) gives you '01/01/(thisyear)'

Upvotes: 1

John Woo
John Woo

Reputation: 263733

SELECT ...
FROM   ...
WHERE DATE_SUB(CURDATE(), INTERVAL 1 YEAR) <= date AND
      YEAR(your_datecolumn) = YEAR(CURDATE())

Upvotes: 2

Related Questions