66

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

Brad Koch
  • 19,267
  • 19
  • 110
  • 137
bsytKorbi
  • 701
  • 1
  • 6
  • 4

4 Answers4

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.

Brad Koch
  • 19,267
  • 19
  • 110
  • 137
Alex
  • 2,247
  • 1
  • 27
  • 37
7
Select current_timestamp;
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
3

just use NOW()

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

Proteux
  • 213
  • 2
  • 3