Solved

MySQL: Replace non alphanumeric with _ in NOW()

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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