Getting timestamp using MySQL

MysqlTimestamp

Mysql Problem Overview


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

Mysql Solutions


Solution 1 - Mysql

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

Solution 2 - Mysql

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.

Solution 3 - Mysql

Select current_timestamp;

Solution 4 - Mysql

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbsytKorbiView Question on Stackoverflow
Solution 1 - MysqlBrad KochView Answer on Stackoverflow
Solution 2 - MysqlAlexView Answer on Stackoverflow
Solution 3 - MysqlPablo Santa CruzView Answer on Stackoverflow
Solution 4 - MysqlProteuxView Answer on Stackoverflow