---
title: "Date and Time function in SQL Server"  
description: "In SQL Server, the following date and time function are used:  Dateadd()It is used to add an interval to a date.Syntax:DATEADD (datepart, number, expr"  
author: "Amit Singh"  
published: 2011-01-31  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/106/date-and-time-function-in-sql-server  
category: "database"  
tags: ["database"]  
reading_time: 2 minutes  

---

# Date and Time function in SQL Server

In [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server), the following date and time [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) are used:\

##### Dateadd()

It is used to add an interval to a date.

##### Syntax:

DATEADD (datepart, number, [expression](https://www.mindstick.com/articles/1861/sqlite-expressions))

##### Example:

SELECT DATEADD(day, 09,'2011-02-06 01:03:00.000')

##### Output:

2011-02-15 01:03:00.000

##### Datediff()

The DATEDIFF function is used to [calculate the difference](https://www.mindstick.com/forum/160701/how-to-calculate-the-difference-between-two-dates-in-c-sharp) between two days.

##### Syntax:

DATEDIFF (datepart, expression1, expression2)

##### Example:

SELECT DATEDIFF(day, '2011-01-11','2011-01-06')

##### Output:

-5

##### Datename()

It Returns a [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) string representing the specified datepart of the specified date.

##### Syntax:

DATENAME (datepart,date)

##### Example:

SELECT DATENAME(month, GETDATE())

##### Output:

January

##### Datepart()

It provides a specific part of the date/time value.

##### Syntax:

DATEPART (part_of_day, expression)

##### Example:

SELECT DATEPART (yyyy,'2011-02-15')

##### Output:

2011

##### Getdate()

It is used to [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) the current [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) system time in SQL Server.

##### Syntax:

GETDATE()

**Note**: it does not contain any parameter.

##### Example:

Select GETDATE()

##### Output:

2011-01-31 20:47:17.270

##### Getutcdate()

It returns the [datetime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) value that represents the current UTC time

##### Syntax:

Getutcdate()

#### Example:

Getutcdate()

Output:

2011-01-31 15:18:01.180

##### Year()

It returns an integer that represents the year of the specified date.

##### Syntax:

YEAR (date)

##### Example:

Select Year(getdate())

##### Output:

2011

##### Month()

It returns an integer that represents the month of the specified date.

Syntax:

Month(date)

##### Example:

Select month(getdate())

##### Output:

1

##### Day()

It returns an integer that represents the day of the specified date.

##### Syntax:

Day(date)

Example:

Select Day(getdate())

##### Output:

31

---

Original Source: https://www.mindstick.com/blog/106/date-and-time-function-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
