Solved

Converting Phone Number

Posted on 2014-04-14
2
292 Views
Last Modified: 2014-04-14
The phone numbers in my DB have this format:
(307)266-3290

I would like to convert them all to this format:
307-266-3290

I think I have to use SELECT CONCAT but not sure how to write the query or optionally just change the output in php.
0
Comment
Question by:seopti
2 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39999175
select concat(concat(substr(PhoneNo,2,3),"-"),substr(PhoneNo,6)) as NewPhoneNo

Replace PhoneNo with the valid field in two places in the above> Of course if you want to change it, it will be an update. I'd run the select first and get that right before updating.
When ready,
Update yourtable
set PhoneNo=concat(concat(substr(PhoneNo,2,3),"-"),substr(PhoneNo,6))

or whatever works in the select
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 39999188
Using php:

$number = "(307)266-3290";
$token = array("(", ")");
$replacement = array("", "-");
$number = str_replace($token, $replacement, $number);
echo $number;

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now