Solved

MySQL: Replace non alphanumeric with _ in NOW()

Posted on 2014-01-24
1
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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