Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if date occurs today?

Tags:

mysql

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.

like image 321
Alt-Rock Ninja Cowgirl Avatar asked Nov 17 '09 01:11

Alt-Rock Ninja Cowgirl


1 Answers

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)

like image 184
Cody Caughlan Avatar answered Nov 15 '22 23:11

Cody Caughlan