gatzkerob
gatzkerob

Reputation: 899

MySQL replace a character with a space

WOW... Using MySQL, is there a way to replace the third "-" from the left in the following timestamp:

2012-06-05-23:48:10

You'd think after an hour of searching I would have found something..

Upvotes: 0

Views: 139

Answers (3)

Raekye
Raekye

Reputation: 5131

MySQL is a relational database management system; it's not for manipulating data.

Instead you would use a programing or scripting language like php to query the database, pull the data into a string, change it, and update the databse. Edit: I'm told that this is possible, but as another user stated there's no direct solution in pure MySQL.

Upvotes: -1

Jason S
Jason S

Reputation: 61

For this, it makes more sense for the data to be saved using the standard but given back as the way your application would use it. This post explains what you are looking for.

Upvotes: 0

Pekka
Pekka

Reputation: 449783

The literal replace operation that you describe is probably beyond the abilities of pure mySQL - it has regex capabilities, but only for matching.

However, one workaround comes to mind:

that said, storing the date as a native DATETIME field in the first place would be a good idea anyway.

Upvotes: 4

Related Questions