bsytKorbi
bsytKorbi

Reputation: 701

Getting timestamp using MySQL

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

Upvotes: 66

Views: 108280

Answers (4)

Brad Koch
Brad Koch

Reputation: 20267

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();

Upvotes: 123

Alex
Alex

Reputation: 2335

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.

Upvotes: 13

Proteux
Proteux

Reputation: 213

just use NOW()

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

Upvotes: 3

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181270

Select current_timestamp;

Upvotes: 7

Related Questions