Home » T-SQL Date functions

T-SQL Date functions

by Online Tutorials Library

T- SQL- Date Functions

In T-SQL, Date functions are used to generate the query for date and time.

GETDATE ():

GETDATE () returns the current date with the time.

Syntax:

The syntax of the function-

Example

The query will return the current date in T-SQL.

DATEPART ()

It gives the part of the date or time.

Syntax

The syntax of the function –

Example

The query returns the part of the current month in T-SQL.

DATEADD ()

It displays the date and time by subtracting or adding the date and time interval.

Syntax

The syntax for the function –

Example

The query below will return after the date and time of ten days from the current date and time in T-SQL.

DATEDIFF()

DATEDIFF () displays the date and time between one or many dates.

Syntax:

Example

The query below returns the gap of hours between 2020-10-12 and 2020-10-09 in MS SQL Server.

CONVERT ()

It displays the date and time in various formats.

Syntax:

Example

The queries return the date and time in many formats in Transact-SQL.


You may also like