Making month MONTH() return zero padded values
Posted: Mon Apr 30, 2007 12:16 pm
Is there a simple way to make the MONTH() function return zero padded values, so 01-12 instead of 1-12? I would like to handle this in the query and not by iterating through the result just to sprintf() it.
Update: some creative thinking has lead me to the following query. It works. However, I feel like this should be done in a more straightforward way.
Code: Select all
SELECT MONTH(date_field) FROM tableUpdate: some creative thinking has lead me to the following query. It works. However, I feel like this should be done in a more straightforward way.
Code: Select all
SELECT SUBSTRING(CONCAT('0', MONTH(date_field)) FROM -2 FOR 2) FROM table