r/DatabaseHelp • u/Gaming_Ruru • Mar 05 '18
Comparing dates
What is the difference between these two: Date is an attribute
1: Status is NULL
CASE WHEN Date < NOW() THEN 'UPCOMING'
WHEN Date = NOW() THEN 'ON GOING'
END AS Status
FROM eventtable WHERE DATE_FORMAT(Date,'%m %d %Y') < NOW() ORDER BY Date DESC LIMIT 12: Status is either UPCOMING or ON GOING
CASE WHEN DATE_FORMAT(Date,'%m %d %Y') < NOW() THEN 'UPCOMING'
WHEN DATE_FORMAT(Date,'%m %d %Y') = NOW() THEN 'ON GOING'
END AS Status
FROM eventtable WHERE DATE_FORMAT(Date,'%m %d %Y') < NOW() ORDER BY Date DESC LIMIT 1
2
Upvotes
View all comments
Show parent comment
1
u/wolf2600 Mar 05 '18
Also, you're filtering on
WHERE DATE_FORMAT(Date,'%m %d %Y') < NOW()So you will never have any of the entries be = NOW()... and when using NOW(), it uses a timestamp, so your Date would have to be exactly equal to NOW, down to the millisecond (not just the day), so explicitly casting to a date might work better:
DATE(Date) > DATE(NOW())