对于以下查询
SELECT
Now() + INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY as 'Due Date',
device_serial as "Device Serial",
customer_name as "Customer",
error_code as 'Error Code',
resolutiom as 'Resolution'
FROM preventive_maintenance
ORDER BY 'Due Date' desc
LIMIT 25
如何解析“到期日”以2019年2月2日的格式显示
答案 0 :(得分:1)
我认为最好在应用程序代码中执行此操作,可以根据最终用户的语言环境将其呈现,但是如果必须在MySQL中执行,则DATE_FORMAT是要使用的函数,例如:
SELECT DATE_FORMAT('2019-02-02','%a-%b-%y') x;
+------------+
| x |
+------------+
| Sat-Feb-19 |
+------------+
答案 1 :(得分:-1)
我已经使用CURDATE()代替了Now()
SELECT
DATE_FORMAT(DATE_ADD(curdate(), INTERVAL FLOOR(RAND()*(1000-5+1)+5) DAY), '%d-%b-%y') as 'Due Date',
device_serial as "Device Serial",
customer_name as "Customer",
error_code as 'Error Code',
resolutiom as 'Resolution'
FROM preventive_maintenance
ORDER BY 'Due Date' desc
LIMIT 25