GETDATE() and CURRENT_TIMESTAMP return the server’s current date and time.
Use GETDATE()
or CURRENT_TIMESTAMP
. Both return the current date-time from the SQL Server instance, including milliseconds, in the datetime
data type.
Wrap the function with CAST( … AS date)
or use CONVERT(date, …)
to strip the time component.
Apply FORMAT()
or CONVERT(varchar, …, style)
. For example, FORMAT(GETDATE(),'yyyy-MM-dd')
returns an ISO-8601 date string.
The query filters todays rows in the Orders
table by comparing order_date
to CAST(GETDATE() AS date)
. This ensures time is ignored.
Store dates in UTC when possible, keep calculations in SQL to avoid client-side drift, and prefer SYSUTCDATETIME()
if you need microsecond precision in UTC.
Avoid comparing a datetime
column directly to GETDATE()
when you intend a date-only match; always cast both sides to date
. Also, dont format the date for comparison—formatting is for display only.
GETDATE() returns the server’s local time zone. Use SYSUTCDATETIME() for UTC.
No. Each call within a query can return slightly different values. Use a variable to store the value once if exact consistency is required.