Reputation: 548
Is there a way to format mysql NOW() So i would get something like year month day hours minutes seconds, all together, like this:
20130822143222
or to get something like microtime() in PHP, but for MySQL?
I need it for the trigger before insert. Thank you :)
Upvotes: 2
Views: 22602
Reputation: 123
In Mysql use Now() function to date & DATE_FORMAT function sql .
select DATE_FORMAT(NOW(),'%d/%m/%Y %H:%i:%s') as date;;
Output:
date
24/01/2024 15:54:32
Upvotes: 0
Reputation: 1420
Using EXTRACT function:
"Select EXTRACT(YEAR from NOW()) as year, EXTRACT(MONTH from NOW()) as month, EXTRACT(DAY
from NOW()) as day, EXTRACT(HOUR from NOW()) as hour, EXTRACT(MINUTE from NOW()) as
minute, EXTRACT(SECOND from NOW()) as second, EXTRACT(MICROSECOND from NOW()) as
microsecond, EXTRACT(MINUTE_MICROSECOND from NOW()) as minute_microsecond";
Upvotes: 0
Reputation: 23610
Besides DATE_FORMAT
this should work too: SUBSTRING(NOW() + 0, 1, 8)
.
Upvotes: 0
Reputation: 1429
You could use string replace functions to remove dashes, colons and spaces from the output of NOW()
as it just returns a string that has exactly what you want, separated by punctuation is listed above. See http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
Upvotes: 0