T-SQL GETDATE() Function

The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.

Examples

Return the current database system date and time

SELECT GETDATE();

Number of Records: 1
Value: 2024-05-05 20:08:57.923

Examples: Just date, Just Time, Just Day, Month or Year

current database system info

SQL

Result

current database system info

SQL

Result

date and time

SELECT GETDATE();

2024-05-05 20:08:57.923

date

SELECT CONVERT(DATE, GETDATE());

2024-05-05

time

20:08:57.923

year

2024

Examples: Parts of a Date (Day, Month, Year)

In most cases DATEADD combines extracting parts of a date with addition or subtraction.

  • Last 7 days: DATEADD(DAY, - 7, GETDATE())

  • One calendar month ago: DATEADD(MONTH, - 1, GETDATE())

NOTES

Works in:

SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse

Related Date Functions

 

Source of date & time

Format

SQL Standard

 

Source of date & time

Format

SQL Standard

GETDATE()

current database system date and time

'YYYY-MM-DD hh:mm:ss.mmm'

Microsoft
T-SQL

CURRENT_TIMESTAMP

current date and time

'YYYY-MM-DD hh:mm:ss.mmm'

ANSI

DATEPART (YEAR, GetDate())

see GETDATE()

‘YY’ integer

Microsoft
T-SQL

DATEADD(…)

argument in ()

 

 

 

Related Pages

 

Â