How can I get the current timestamp using a mysql query?
Asked
Active
Viewed 1e+01k times
4 Answers
119
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();

Brad Koch
- 19,267
- 19
- 110
- 137
-
How do I change this? It is set to UTC I want to change it to IST +0530. I have root access to Ubuntu – Donnie Ashok Jan 16 '18 at 07:54
-
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`](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_convert-tz), or setting the default time zone using one of the [methods in the docs](https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html). – Brad Koch Jan 16 '18 at 14:31
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.
-
3inserting CURRENT_TIMESTAMP in a bigint will not store a unix timestamp – Alain Tiemblo Sep 28 '16 at 13:47
3
just use NOW()
Full reference: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Proteux
- 213
- 2
- 3