By: Daniel Calbimonte
The CURRENT_TIMESTAMP function returns the current server time stamp using the datetime format. This function is an ANSI SQL standard and it returns the same value the GETDATE() function returns. It is recommended to use this function instead of GETDATE(), because this function is an ANSI standard while GETDATE() is a SQL Server specific function.
Syntax
CURENT_TIMESTAMP
Parameters
- No parameters required
Simple CURRENT_TIMESTAMP Example
The following is a simple CURRENT_TIMESTAMP example.
SELECT CURRENT_TIMESTAMP as timestamp
Difference between GETDATE() and CURRENT_TIMESTAMP
The following example shows that there are differences between the GETDATE() function and CURRENT_TIMESATAMP.
SELECT DATEDIFF(SECOND, GETDATE(), CURRENT_TIMESTAMP) as difference
How to set the CURRENT_TIMESTAMP with a Custom Format
The following example will show the CURRENT_TIMESTAMP in the dd-MM-yyyy hh:mm:ss tt format.
SELECT FORMAT(CURRENT_TIMESTAMP, 'dd-MM-yyyy hh:mm:ss tt') as formatdate
How to set the CURRENT_TIMESTAMP with a Different Cultural Format
The following example will set the CURRENT_TIMESTAMP in the Japanese date format.
SELECT FORMAT (CURRENT_TIMESTAMP, 'dddd dd, MMMM, yyyy', 'ja-jp') as japanese
Using CURRENT_TIMESTAMP with Data from a Table
The following example will show ProductIDs with a StartDate between 8 and 9 years ago using CURRENT_TIMESTAMP as the current time.
SELECT Productid, DATEDIFF(YEAR, StartDate, CURRENT_TIMESTAMP) as years FROM Production.ProductCostHistory WHERE DATEDIFF(YEAR, StartDate, CURRENT_TIMESTAMP) BETWEEN 8 AND 9
Related Articles
- How to Get Current Date in SQL Server
- Mimic timestamp behavior of other database platforms to store last modified date
- SQL Convert Date to YYYYMMDD
- SQL DATEDIFF
Last Update: 1/4/2022