This section provides a comprehensive reference to the Transact-SQL (T-SQL) functions available for working with date and time data types in SQL Server.
Returns the current database system timestamp as a datetime2(3) value.
Returns the date and time of the server on which the instance of SQL Server is running.
Returns a specified date with a specified time interval added to it.
Returns the number of date and time parts between two specified dates.
Returns an integer representing the specified date part of the specified date.
Returns a character string representing the specified date part of the specified date.
Returns the day of the month for a specified date.
Returns an integer that represents the month of a specified date.
Returns an integer that represents the year of a specified date.
Formats a value and converts it to text in a specified format.
Determines whether the input expression is a valid date or time.
Changes the offset of a datetimeoffset value to a specified offset.
Converts various date and time data types to datetime2.
Converts various date and time data types to datetimeoffset.
Returns the current database system timestamp as a datetime2(3)
value.
GETDATE()
is a non-deterministic function. The value returned by the function can be different each time it is executed.
Returns the date and time of the server on which the instance of SQL Server is running.
SYSDATETIME()
is a non-deterministic function. The value returned by the function can be different each time it is executed.
Returns a specified date with a specified time interval added to it.
Parameters:
datepart: The part of the date to which the number is added. For a list of valid datepart values, see Datepart Values.
number: The integer expression that represents the number of units to add.
date: The date expression on which you are operating.
Returns the number of date and time parts between two specified dates.
Parameters:
datepart: The part of the date for which the difference is returned. For a list of valid datepart values, see Datepart Values.
startdate: The first date expression.
enddate: The second date expression.
Returns an integer representing the specified date part of the specified date.
Parameters:
datepart: The part of the date to return. For a list of valid datepart values, see Datepart Values.
date: The date expression on which you are operating.
Returns a character string representing the specified date part of the specified date.
Parameters:
datepart: The part of the date to return. For a list of valid datepart values, see Datepart Values.
date: The date expression on which you are operating.
Returns the day of the month for a specified date.
Parameters:
date: The date expression.
Returns an integer that represents the month of a specified date.
Parameters:
date: The date expression.
Returns an integer that represents the year of a specified date.
Parameters:
date: The date expression.
Formats a value and converts it to text in a specified format.
Parameters:
value: The value to format. Can be any expression that returns a date, time, or number.
format: The format string. Can be a standard format string or a custom format string.
culture: Optional. The culture to use for formatting. If not specified, the current session culture is used.
Determines whether the input expression is a valid date or time.
Parameters:
string: The expression to test.
ISDATE
returns 1 if the string is a valid date or time, and 0 otherwise.
Changes the offset of a datetimeoffset value to a specified offset.
Parameters:
datetimeoffset_expression: An expression of the datetimeoffset data type.
timezoneoffset: The new time zone offset to apply to the datetimeoffset value. The offset is specified in the format +HH:MM or -HH:MM.
Converts various date and time data types to datetime2.
Parameters:
input: An expression of any valid date and time data type.
date_style: Optional. An integer that specifies the style of the input date.
Converts various date and time data types to datetimeoffset.
Parameters:
expression: An expression of any valid date and time data type.
timezoneoffset: Optional. The time zone offset to apply to the converted value.
year
, yy
, yyyy
quarter
, qq
, q
month
, mm
, m
dayofyear
, dy
, y
day
, dd
, d
week
, wk
, ww
weekday
, dw
, w
hour
, hh
minute
, mi
, n
second
, ss
, s
millisecond
, ms
microsecond
, mcs
nanosecond
, ns