Monday, 25 May 2009

SQL Server Date Time Functions

GETDATE()
Returns the current system date and time in the SQL Server standard internal format for datetime values.

DATEPART(datepart, date)
Returns an integer that represents the specified datepart of the specified date.

DATENAME(datepart, date)
Returns a character string representing the specified datepart of the specified date.

DATEADD(datepart, diffNum, date)
Returns a new datetime value based on adding an interval to the specified date.

DATEDIFF(datepart, date1, date2)
Returns the number of date and time boundaries crossed between two specified dates.

Year(date), Month(date), Day(date) are working exactly same with DATENAME(year/month/day, date)

The param datepart is the parameter that specifies on which part of the date to calculate the difference.

No comments: