top of page

How to Use Date Functions in SQL Server | SQL Server Tutorial

Updated: Dec 29, 2024

SQL Server has several different date and time functions and trying to remember every function is not that easy.  So, I put together this tutorial that shows the different date and time functions all in one place along with examples to make finding what you are looking for much easier.




Create Complete Login Form





1 - SQL Server CURRENT_TIMESTAMP Function


The CURRENT_TIMESTAMP function returns the current date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.

Tip: Also look at the GETDATE() function.

Syntax:-

CURRENT_TIMESTAMP



2 - SQL Server DATEADD() Function


The DATEADD() function adds a time/date interval to a date and then returns the date.

Syntax:-

DATEADD(interval, number, date)


3 - SQL Server DATEDIFF() Function


The DATEDIFF() function returns the difference between two dates, as an integer.

Syntax:-

DATEDIFF(interval, date1, date2)


4 - SQL Server DATENAME() Function


The DATENAME() function returns a specified part of a date.

This function returns the result as a string value.

Syntax:-

DATENAME(interval, date)

5- SQL Server DATEPART() Function

The DATEPART() function returns a specified part of a date.

This function returns the result as an integer value.

Syntax:-

DATEPART(interval, date)

    

6- SQL Server MONTH() Function

The MONTH() function returns the month part for a specified date (a number from 1 to 12).

Syntax:-

MONTH(date)


7- SQL Server YEAR() Function

The YEAR() function returns the year part for a specified date.

Syntax:-

YEAR(date)


Summary


From the preceding all examples we have learned how to Use SQL Date Functions . I hope you understand it.

 
 
 

Comments


bottom of page