67

How can I get the current timestamp using a mysql query?

4 Answers 4

125

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();
Sign up to request clarification or add additional context in comments.

2 Comments

How do I change this? It is set to UTC I want to change it to IST +0530. I have root access to Ubuntu
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.
13

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

inserting CURRENT_TIMESTAMP in a bigint will not store a unix timestamp
7
Select current_timestamp;

Comments

3

just use NOW()

Full reference: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

1 Comment

now() return date+time instead of timestamp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.