QA Graphic

Common T-SQL Functions

There are some of  the most used Date/Time functions in SQL Server 2008:

  • GetDate() - Current system date and time
  • DateAdd() - A date produced by adding date parts to another date
  • DatePart() - Part of a datetime or smalldatetime value (for example, the month) as an integer
  • DateDiff() - The amount of time between the second and first of two dates, converted to the specified date part (for example, months, days, hours)
  • DateName() - Part of a datetime or smalldatetime value as an ASCII string
  • Day() - Displays the day in a datetime field
  • Month() - Displays the month in a datetime field
  • Year() - Displays the year in a datetime field

This is the most commonly use Date Query. It returns the current date in the following format: August 12, 2011

SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY]