MySQL CURRENT_TIMESTAMP() function
CURRENT_TIMESTAMP() function
In MySQL, the CURRENT_TIMESTAMP returns the current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYYMMDDHHMMSS.uuuuuu format depending on whether numeric or string is used in the function. NOW() and CURRENT_TIMESTAMP() are the synonym of CURRENT_TIMESTAMP.
Note: All of the example codes of this page will produce outputs depending upon the current date.
This function is useful in -
- The primary purpose of the CURRENT_TIMESTAMP() function is to provide an accurate timestamp of the current date and time.
- For audit trails, logging, or compliance purposes, CURRENT_TIMESTAMP() offers a high level of accuracy in tracking when specific actions were taken.
- CURRENT_TIMESTAMP() is used to compare the current timestamp with other timestamps stored in the database.
- This is useful for filtering and querying data based on time intervals, date ranges, and specific moments in time.
- CURRENT_TIMESTAMP() accounts for the time zone of the database server, ensuring that the timestamp reflects the server's time zone.
- In performance analysis, CURRENT_TIMESTAMP() helps track the duration of specific operations or processes accurately.
- For ensuring data integrity, CURRENT_TIMESTAMP() helps maintain accurate records of when data changes were made.
Syntax:
CURRENT_TIMESTAMP;
Syntax Diagram:
MySQL Version: 8.0
Pictorial Presentation:
Example-1: MySQL CURRENT_TIMESTAMP
The following statement will return the current date and time in ‘YYYY-MM-DD HH:MM:SS’ format.
Code:
SELECT CURRENT_TIMESTAMP;
Output:
mysql> SELECT CURRENT_TIMESTAMP; +---------------------+ | CURRENT_TIMESTAMP | +---------------------+ | 2015-04-13 11:42:41 | +---------------------+ 1 row in set (0.00 sec)
Example-2
The following statement will return the current date and time in ‘YYYY-MM-DD HH:MM:SS’ format.
Code:
SELECT CURRENT_TIMESTAMP();
Output:
mysql> SELECT CURRENT_TIMESTAMP(); +---------------------+ | CURRENT_TIMESTAMP() | +---------------------+ | 2015-04-13 11:43:47 | +---------------------+ 1 row in set (0.00 sec)
Video Presentation:
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
Previous: CURRENT_TIME()
Next: CURTIME()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mysql/date-and-time-functions/mysql-current_timestamp-function.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics