Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL function 2 digit number formatting

Tags:

sql

mysql

Is there any SQL function to convert the number in two digit numbers so, I can get 01 for 1.

like image 266
hsuk Avatar asked Jul 04 '26 08:07

hsuk


2 Answers

You need to convert the value into string. You can use LPAD() for this,

  • SQLFiddle Demo
  • LPAD()
like image 130
John Woo Avatar answered Jul 07 '26 07:07

John Woo


It would be:

SELECT LPAD(1, 2, '0');

Live Demo

like image 38
Vishal Suthar Avatar answered Jul 07 '26 07:07

Vishal Suthar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!