NateB NateB - 6 months ago 43
MySQL Question

how do I add a leading zero to a column?

So I am importing a customer table and the date values are missing the leading zero for the month, so month column has a value of 2 instead of 02. How can I add a leading zero to the effected dates without adding a zero to dates where the leading zero is no issue? Any help is appreciated. Thanks


Try select right(concat('0', <YourMonth>), 2).

Alternatively you could use the MySQL LPAD function, but this is a handy technique to know that you can also use in Excel.