Muokkaa

Jaa


CURRENT_DATE (Transact-SQL)

Applies to: Azure SQL Database Azure SQL Managed Instance

In Azure SQL Database and Azure SQL Managed Instance, this function returns the current database system date as a date value, without the database time and time zone offset. CURRENT_DATE derives this value from the underlying operating system on the Database Engine runs.

Note

SYSDATETIME and SYSUTCDATE have more precision, as measured by fractional seconds precision, than GETDATE and GETUTCDATE. The SYSDATETIMEOFFSET function includes the system time zone offset. You can assign SYSDATETIME, SYSUTCDATETIME, and SYSDATETIMEOFFSET to a variable of any of the date and time types.

This function is the ANSI SQL equivalent to CAST(GETDATE() AS DATE). For more information, see GETDATE.

See Date and time data types and functions for an overview of all the Transact-SQL date and time data types and functions.

Transact-SQL syntax conventions

Syntax

Azure SQL Database and Azure SQL Managed Instance only:

CURRENT_DATE

Arguments

This function takes no arguments.

Return types

date

Remarks

Transact-SQL statements can refer to CURRENT_DATE anywhere they can refer to a date expression.

CURRENT_DATE is a nondeterministic function. Views and expressions that reference this column can't be indexed.

Examples

These examples use the system functions that return current date and time values, to return the date, the time, or both. The examples return the values in series, so their fractional seconds might differ. The actual values returned reflect the actual day / time of execution.

A. Get the current system date and time

SELECT SYSDATETIME(),
    SYSDATETIMEOFFSET(),
    SYSUTCDATETIME(),
    CURRENT_TIMESTAMP,
    GETDATE(),
    GETUTCDATE(),
    CURRENT_DATE;

Note

CURRENT_DATE (Transact-SQL) is available in Azure SQL Database and Azure SQL Managed Instance only.

Here's the result set.

Data type Value
SYSDATETIME() 2024-06-26 14:04:21.6172014
SYSDATETIMEOFFSET() 2024-06-26 14:04:21.6172014 -05:00
SYSUTCDATETIME() 2024-06-26 19:04:21.6172014
CURRENT_TIMESTAMP 2024-06-26 14:04:21.617
GETDATE() 2024-06-26 14:04:21.617
GETUTCDATE() 2024-06-26 19:04:21.617
CURRENT_DATE 2024-06-26

B. Get the current system date

SELECT CONVERT(DATE, SYSDATETIME()),
    CONVERT(DATE, SYSDATETIMEOFFSET()),
    CONVERT(DATE, SYSUTCDATETIME()),
    CONVERT(DATE, CURRENT_TIMESTAMP),
    CONVERT(DATE, GETDATE()),
    CONVERT(DATE, GETUTCDATE()),
    CURRENT_DATE;

Note

CURRENT_DATE (Transact-SQL) is available in Azure SQL Database and Azure SQL Managed Instance only.

Here's the result set.

Data type Value
SYSDATETIME() 2024-06-26
SYSDATETIMEOFFSET() 2024-06-26
SYSUTCDATETIME() 2024-06-26
CURRENT_TIMESTAMP 2024-06-26
GETDATE() 2024-06-26
GETUTCDATE() 2024-06-26
CURRENT_DATE 2024-06-26