Solved

MySQL: Replace non alphanumeric with _ in NOW()

Posted on 2014-01-24
1
336 Views
Last Modified: 2014-01-24
This:
SELECT (REPLACE(NOW() ,'[0-9]+','_'))

Open in new window

returns this:
2014-01-24 07:48:31
How can I get this?
2014_01_24_07_48_31
0
Comment
Question by:hankknight
1 Comment
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39806910
You can't replace multiple characters like that, so you could nest three REPLACE statements to remove the -, : and space:

SELECT REPLACE(REPLACE(REPLACE(NOW() ,'-','_'),':', '_'), ' ', '_')

Alternatively if it's to get a specific format for your date, then just use DATE_FORMAT:

SELECT DATE_FORMAT(NOW(),'%Y_%m_%d_%H_%i_%s');
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

789 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