SQL Server CURRENT_TIMESTAMP: How to Use It
In this article
CURRENT_TIMESTAMP in SQL Server is a niladic function that returns the current date and time as a datetime value. It is the ANSI SQL equivalent of GETDATE() and requires no arguments. Because it is evaluated once per statement (not per row), it is the safe way to stamp a batch of rows with a single consistent timestamp. You do not need to install anything extra: any SQL Server instance (Express, Standard, Enterprise, Azure SQL) includes it. You only need a connection to the database and permission to run a query.
What You'll Need
- Access to a SQL Server instance (on-premises or Azure SQL Database).
- A client tool such as SQL Server Management Studio (SSMS), Azure Data Studio, or
sqlcmd. - A database where you can run a
SELECTstatement (themasterdatabase works for testing). - Basic familiarity with T-SQL
SELECTsyntax.
Step-by-Step
- Connect to your SQL Server instance. Open SSMS or Azure Data Studio, enter the server name, choose authentication, and click Connect. In
sqlcmd, runsqlcmd -S server_name -U user -P password. - Select a database (optional). Run
USE YourDatabaseName;if you want to test inside a specific database.CURRENT_TIMESTAMPdoes not depend on the database context, so you can skip this for a quick test. - Run the basic query. Execute
SELECT CURRENT_TIMESTAMP;. You should see a single column with the server's current date and time, for example2025-01-15 14:32:07.123. - Alias the column for readability. Use
SELECT CURRENT_TIMESTAMP AS NowTime;so the result column has a meaningful name. - Check the data type. Run
SELECT SQL_VARIANT_PROPERTY(CURRENT_TIMESTAMP, 'BaseType') AS DataType;. It returnsdatetime. If you need more precision, useSYSDATETIME(), which returnsdatetime2. - Insert the timestamp into a table. Create a test table:
CREATE TABLE dbo.Events (EventID int IDENTITY, EventName nvarchar(50), CreatedAt datetime DEFAULT CURRENT_TIMESTAMP);. Then insert a row:INSERT INTO dbo.Events (EventName) VALUES ('Test');and query it:SELECT * FROM dbo.Events;. TheCreatedAtcolumn is filled automatically. - Use it in a WHERE clause. For example,
SELECT * FROM dbo.Events WHERE CreatedAt < CURRENT_TIMESTAMP;returns all rows created before now. Because the function is evaluated once, all rows in the result use the same cutoff time. - Compare with GETDATE(). Run
SELECT CURRENT_TIMESTAMP AS ANSI_Time, GETDATE() AS TSQL_Time;. Both return the same value in a single statement.CURRENT_TIMESTAMPis the portable, ANSI-standard name;GETDATE()is the T-SQL-specific name. - Use it in a DEFAULT constraint for audit columns. Add a column with
ALTER TABLE dbo.Events ADD ModifiedAt datetime DEFAULT CURRENT_TIMESTAMP;. New rows get the timestamp automatically; existing rows keep NULL unless you update them. - Format the output if needed. Wrap it in
CONVERTorFORMAT, for exampleSELECT CONVERT(varchar(19), CURRENT_TIMESTAMP, 120) AS FormattedTime;givesYYYY-MM-DD HH:MM:SS. AvoidFORMATon large result sets because it is slower.
Common Mistakes
- Assuming it returns local time.
CURRENT_TIMESTAMPreturns the server's local time, which may be UTC in cloud environments. If you need UTC explicitly, useSYSUTCDATETIME(). - Expecting per-row values. The function is evaluated once per statement. If you insert 1,000 rows in one
INSERT ... SELECT, every row gets the same timestamp. UseSYSDATETIME()if you need finer precision, but it is still statement-level. - Using it without parentheses.
CURRENT_TIMESTAMPis niladic, soCURRENT_TIMESTAMP()is a syntax error. Write it without parentheses. - Confusing it with
CURRENT_DATE. SQL Server does not have aCURRENT_DATEfunction. UseCAST(CURRENT_TIMESTAMP AS date)orCONVERT(date, CURRENT_TIMESTAMP)to get just the date. - Storing it in a
datetime2column without conversion. Implicit conversion works, but explicitCASTorCONVERTavoids surprises with precision. - Relying on it for unique ordering. Two statements in the same millisecond can return the same value. Use an identity column or a sequence for ordering.
Tips
- Use
CURRENT_TIMESTAMPinDEFAULTconstraints for audit columns likeCreatedAtandModifiedAt; it keeps inserts simple. - For UTC timestamps in cloud or multi-region setups, prefer
SYSUTCDATETIME()and store UTC consistently. - When comparing dates, cast both sides to the same type:
WHERE CAST(CreatedAt AS date) = CAST(CURRENT_TIMESTAMP AS date). - Use
SET NOCOUNT ON;in scripts that insert many rows to reduce network traffic. - Test time-zone behavior on your server with
SELECT SYSDATETIMEOFFSET();to see the offset.
Troubleshooting
- Error: "'CURRENT_TIMESTAMP' is not a recognized built-in function name." This happens if you add parentheses. Remove them:
SELECT CURRENT_TIMESTAMP;. - Unexpected time value. Check the server's time zone with
SELECT SYSDATETIMEOFFSET();. If the server is in UTC but you expected local time, convert explicitly or change the server configuration (requires admin rights). - Permission denied. You need
SELECTpermission on the database or table. Ask your DBA to grant it. - Default constraint not applying. Verify the column has a default:
SELECT name, definition FROM sys.default_constraints WHERE parent_object_id = OBJECT_ID('dbo.Events');. If missing, add it withALTER TABLE. - Different results in different sessions. Each session uses the server's clock. If you are connected to different instances, the times will differ.
Frequently Asked Questions
Is CURRENT_TIMESTAMP the same as GETDATE()?
Yes, in SQL Server they return the same datetime value. CURRENT_TIMESTAMP is ANSI-standard; GETDATE() is T-SQL-specific. Use whichever fits your portability needs.
Does CURRENT_TIMESTAMP include milliseconds?
It returns a datetime with millisecond precision (three digits after the seconds). For higher precision, use SYSDATETIME(), which returns datetime2 with up to seven digits.
Can I use CURRENT_TIMESTAMP as a column default?
Yes. Define the column as datetime DEFAULT CURRENT_TIMESTAMP and new rows will get the timestamp automatically.
Why does CURRENT_TIMESTAMP return UTC in Azure SQL?
Azure SQL Database runs in UTC by default. CURRENT_TIMESTAMP reflects the server's time zone, which is UTC there. Use AT TIME ZONE to convert to a specific zone.
Can I subtract from CURRENT_TIMESTAMP?
Yes. Use DATEADD, for example SELECT DATEADD(day, -7, CURRENT_TIMESTAMP); returns the time seven days ago.
Is CURRENT_TIMESTAMP evaluated once per row or once per statement?
Once per statement. All rows in a single query see the same value, which is why it is safe for consistent batch timestamps.