num_daysopen
返回自开放日期以来的天数。
剩余天数返回用户关闭某些内容的天数(从开放日期起最多28天)。如果超过28天days_left
需要默认为0而不是-5或-15等
SELECT
DATEDIFF(DATE(NOW()), DATE(dateopened)) AS num_daysopen,
(28 - DATEDIFF(DATE(NOW()), DATE(dateopened))) as days_left
FROM table
答案 0 :(得分:1)
使用GREATEST()。
SELECT
DATEDIFF(DATE(NOW()), DATE(dateopened)) AS num_daysopen,
GREATEST(0,(28 - DATEDIFF(DATE(NOW()), DATE(dateopened)))) as days_left
FROM table