Alt-Rock Ninja Cowgirl
Alt-Rock Ninja Cowgirl

Reputation: 526

How do I check if date occurs today?

Here's what I have.

SELECT 
CASE WHEN 
DATE_FORMAT(a.lastLogin, 'W') = DATE_FORMAT(NOW(), 'W') 
THEN 'Today' 
ELSE 
DATE_FORMAT(a.lastLogin, 'W') 
END AS lastlogin
FROM authors a

I am pretty sure there is a much simpler way to do this that I'm missing.

Upvotes: 14

Views: 18256

Answers (1)

Cody Caughlan
Cody Caughlan

Reputation: 32748

DATE(a.lastlogin) = DATE(NOW())

the DATE() function normalizes a datetime column to just the date portion (e.g. 2009-11-16 16:45:23 would become just 2009-11-16)

Upvotes: 43

Related Questions