How can I get the current timestamp using a mysql query?
4 Answers
Depends on which kind you're looking for.
The current integer Unix Timestamp (1350517005) can be retrieved like so:
SELECT UNIX_TIMESTAMP();
MySQL often displays timestamps as date/time strings. To get one of those, these are your basic options (from the MySQL Date & Time reference):
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_TIMESTAMP();
SELECT NOW();
2 Comments
Donnie Ashok
How do I change this? It is set to UTC I want to change it to IST +0530. I have root access to Ubuntu
Brad Koch
That's worth a new question, but the short answer is that you're probably best off either leaving the server at UTC and using
CONVERT_TZ, or setting the default time zone using one of the methods in the docs.CURRENT_TIMESTAMP is standard SQL and works on SQL server, Oracle, MySQL, etc. You should try to keep to the standard as much as you can.
1 Comment
Alain
inserting CURRENT_TIMESTAMP in a bigint will not store a unix timestamp
just use NOW()
Full reference: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
1 Comment
ajreal
now() return date+time instead of timestamp