[英]Remove leading zeros from %m and %d in MySQL date_format
以下查询生成的日期类似于2016, 01, 02
。 如何从月份和日期中删除尾随零,以便它看起来像2016, 1, 2
?
SELECT DATE_FORMAT(earning_created, '%Y, %m, %d') AS day, SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created
您可以使用%c
格式化月份而不使用前导零和%e
来格式化月中的某一天:
SELECT DATE_FORMAT(earning_created, '%Y, %c, %e') AS day, -- Here!
SUM(earning_amount) AS amount
FROM earnings
WHERE earning_account_id = ?
GROUP BY DATE(earning_created)
ORDER BY earning_created
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.