Solved

MySQL: Replace non alphanumeric with _ in NOW()

Posted on 2014-01-24
1
317 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 42

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

19 Experts available now in Live!

Get 1:1 Help Now