MySQL: Add Leading Zeros
There might be many ways to force leading zeros to be displayed when string length is less than expected.
One of them is to use string function LPAD(). For example, the following query:
SELECT LPAD('1101', 8, '0');
returns ’00001101′.
However, if string (first parameter) is longer than length (second parameter), the return value is shortened. For example:
SELECT LPAD('1101', 2, '0');
returns ’11′.
Comments(5)
Thanks alex
Too me whole day to find this! Thanks!!
Thanks for finding this alex.
Thanks dude!!
Thank you