Skip to main content
Skip table of contents

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

SQL
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

date and time

SQL
SELECT GETDATE();

2024-05-05 20:08:57.923

date

SQL
SELECT CONVERT(DATE, GETDATE());

2024-05-05

time

SQL
SELECT CONVERT(TIME, GETDATE());

20:08:57.923

year

SQL
SELECT YEAR(GETDATE());

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

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

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.