I was wondering if there is a simpler way in MySQL to take a 10 digit phone number 9876543210
and display it in the format (987) 654-3210
. I have code that works fine but I was wondering if there was another way perhaps similar to DATE_FORMAT()
.
The code I'm using:
IF(phone_cell != '',
CONCAT('(',
SUBSTRING(phone_cell, 1, 3),
') ',
SUBSTRING(phone_cell, 4, 3),
'-',
SUBSTRING(phone_cell, 7, 4)),
'') AS Mobile
The part I'm seeking is to replace the CONCAT
statement.
No. Unfortunately, there is no such method as to format the phone number in MySQL.
Your concat
method is working fine.
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