Solved

MySQL: Replace non alphanumeric with _ in NOW()

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert row field data graphically 4 41
mysql disables rename 4 112
MySQL Query Using Up Memory 6 61
Currency in SQL? 2 53
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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