The following query produces a date that looks like this 2016, 01, 02
. How do I get it to remove trailing zeros from the month and day so that it looks like this 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
In Oracle Database, you can use the fm (fill mode) format modifier to suppress any leading zeroes that might be applied to a date. This format modifier suppresses padding, which includes leading zeros and trailing blanks.
You can use str_to_date to convert a date string to MySQL's internal date format for inserting.
The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().
You can use %c
to format the month without the leading zero and %e
to format the day of the month:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With