Skip to main content
Date literal functions begin with L_ and are used to filter date fields using relative intervals. Note that while the <, >, and = operators are supported for date literal functions, <= and >= are not.

CURRENT_DATE

Returns the current date value. Syntax
Examples

CURRENT_TIMESTAMP

Returns the current time stamp of the database system as a datetime value. This value is equal to GETDATE and SYSDATETIME, and is always in the local timezone. Syntax
Examples

DATEADD

Returns the datetime value that results from adding the specified number (a signed integer) to the specified date part of the date. Syntax
Parameters
  • datepart The part of the date to add the specified number to. The valid values and abbreviations are year (yy, yyyy), quarter (qq, q), month (mm, m), dayofyear (dy, y), day (dd, d), week (wk, ww), weekday (dw), hour (hh), minute (mi, n), second (ss, s), and millisecond (ms).
  • number The number to be added.
  • date The expression of the datetime data type.
  • dateformat The optional output date format.
Examples

DATEDIFF

Returns the difference (a signed integer) of the specified time interval between the specified start date and end date. Syntax
Parameters
  • datepart The part of the date that is the time interval of the difference between the start date and end date. The valid values and abbreviations are day (dd, d), hour (hh), minute (mi, n), second (ss, s), and millisecond (ms).
  • startdate The datetime expression of the start date.
  • enddate The datetime expression of the end date.
Examples

DATEFROMPARTS

Returns the datetime value for the specified year, month, and day. Syntax
Parameters
  • year The integer expression specifying the year.
  • month The integer expression specifying the month.
  • day The integer expression specifying the day.
Examples

DATENAME

Returns the character string that represents the specified date part of the specified date. Syntax
Parameters
  • datepart The part of the date to return. The valid values and abbreviations are year (yy, yyyy), quarter (qq, q), month (mm, m), dayofyear (dy, y), day (dd, d), week (wk, ww), weekday (dw), hour (hh), minute (mi, n), second (ss, s), millisecond (ms), microsecond (mcs), nanosecond (ns), and TZoffset (tz).
  • date The datetime expression.
Examples

DATEPART

Returns a character string that represents the specified date part of the specified date. Syntax
Parameters
  • datepart The part of the date to return. The valid values and abbreviations are year (yy, yyyy), quarter (qq, q), month (mm, m), dayofyear (dy, y), day (dd, d), week (wk, ww), weekday (dw), hour (hh), minute (mi, n), second (ss, s), millisecond (ms), microsecond (mcs), nanosecond (ns), TZoffset (tz), ISODOW, ISO_WEEK (isoweek, isowk,isoww), and ISOYEAR.
  • date The datetime string that specifies the date.
  • datefirst The optional integer representing the first day of the week. The default is 7, Sunday.
Examples

DATETIMEFROMPARTS

Returns the datetime value for the specified date parts. Syntax
Parameters
  • year The integer expression specifying the year.
  • month The integer expression specifying the month.
  • day The integer expression specifying the day.
  • hour The integer expression specifying the hour.
  • minute The integer expression specifying the minute.
  • seconds The integer expression specifying the seconds.
  • milliseconds The integer expression specifying the milliseconds.
Examples

DATETIME2FROMPARTS

Returns the datetime value for the specified date parts (with different parameters). Syntax
Parameters
  • year The integer expression specifying the year.
  • month The integer expression specifying the month.
  • day The integer expression specifying the day.
  • hour The integer expression specifying the hour.
  • minute The integer expression specifying the minute.
  • seconds The integer expression specifying the seconds.
  • fractions The integer expression specifying the fractions of the second.
  • precision The integer expression specifying the precision of the fraction.
Examples

DATE_TRUNC

Truncates the date to the precision of the given date part. Modeled after the Oracle TRUNC function. Syntax
Parameters
  • date The datetime string that specifies the date.
  • datepart Refer to the Oracle documentation for valid datepart syntax.
Examples

DATE_TRUNC2

Truncates the date to the precision of the given date part. Modeled after the PostgreSQL date_trunc function. Syntax
Parameters
  • datepart One of ‘millennium’, ‘century’, ‘decade’, ‘year’, ‘quarter’, ‘month’, ‘week’, ‘day’, ‘hour’, ‘minute’ or ‘second’.
  • date The datetime string that specifies the date.
  • weekday The optional day of the week to use as the first day for ‘week’. One of ‘sunday’, ‘monday’, etc.
Examples

DAY

Returns the integer that specifies the day component of the specified date. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

DAYOFMONTH

Returns the day of the month of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

DAYOFWEEK

Returns the day of the week of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

DAYOFYEAR

Returns the day of the year of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

EOMONTH

Returns the last day of the month that contains the specified date with an optional offset. Syntax
Parameters
  • date The datetime expression specifying the date for which to return the last day of the month.
  • integer_month_to_add The optional integer expression specifying the number of months to add to the date before calculating the end of the month.
Examples

FDMONTH

Returns the first day of the month of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

FDQUARTER

Returns the first day of the quarter of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

FDWEEK

Returns the first day of the week of the given date part. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

FILEMODIFIEDTIME

Returns the time stamp associated with the Date Modified of the relevant file. Syntax
Parameters
  • uri An absolute path pointing to a file on the local file system.
Examples

FROM_DAYS

Returns a date derived from the number of days after 1582-10-15 (based upon the Gregorian calendar). This will be equivalent to the MYSQL FROM_DAYS function. Syntax
Parameters
  • datevalue An integer value representing the number of days since 1582-10-15.
Examples

GETDATE

Returns the current time stamp of the database system as a datetime value. This value is equal to CURRENT_TIMESTAMP and SYSDATETIME, and is always in the local timezone. Syntax
Examples

GETUTCDATE

Returns the current time stamp of the database system formatted as a UTC datetime value. This value is equal to SYSUTCDATETIME. Syntax
Examples

HOUR

Returns the hour component from the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

ISDATE

Returns 1 if the value is a valid date, time, or datetime value; otherwise, 0. Syntax
Parameters
  • date The datetime string that specifies the date.
  • date_format The optional datetime format.
Examples

L_LAST_N_DAYS

The previous n days, excluding the current day. Syntax
Examples

L_LAST_N_WEEKS

Every day in every week, starting n weeks before current week, and ending in the previous week. Syntax
Examples

L_LAST_WEEK

Every day in the preceding week. Syntax
Examples

L_NEXT_N_DAYS

The following n days, including the current day. Syntax
Examples
Also available:
  • LAST/NEXT_90_DAYS

L_NEXT_N_WEEKS

Every day in every week, starting the following week, and ending n weeks in the future. Syntax
Examples
Also available:
  • LAST/NEXT_N_MONTHS(n)
  • LAST/NEXT_N_QUARTERS(n)
  • LAST/NEXT_N_YEARS(n)

L_NEXT_WEEK

Every day in the following week. Syntax
Examples
Also available:
  • LAST/THIS/NEXT MONTH
  • LAST/THIS/NEXT QUARTER
  • LAST/THIS/NEXT YEAR

L_THIS_WEEK

Every day in the current week. Syntax
Examples

L_TODAY

The current day. Syntax
Examples

L_TOMORROW

The following day. Syntax
Examples

L_YESTERDAY

The previous day. Syntax
Examples

LAST_MONTH

Returns a time stamp equivalent to exactly one month before the current date. Syntax
Examples

LAST_WEEK

Returns a time stamp equivalent to exactly one week before the current date. Syntax
Examples

LAST_YEAR

Returns a time stamp equivalent to exactly one year before the current date. Syntax
Examples

LDMONTH

Returns the last day of the provided month. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

LDQUARTER

Returns the last day of the provided quarter. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

LDWEEK

Returns the last day of the provided week. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

MAKEDATE

Returns a date value from a year and a number of days. Syntax
Parameters
  • year The year
  • days The number of days into the year. Value must be greater than 0.
Examples

MINUTE

Returns the minute component from the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

MONTH

Returns the month component from the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

QUARTER

Returns the quarter associated with the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

SECOND

Returns the second component from the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

SMALLDATETIMEFROMPARTS

Returns the datetime value for the specified date and time. Syntax
Parameters
  • year The integer expression specifying the year.
  • month The integer expression specifying the month.
  • day The integer expression specifying the day.
  • hour The integer expression specifying the hour.
  • minute The integer expression specifying the minute.
Examples

STRTODATE

Parses the provided string value and returns the corresponding datetime. Syntax
Parameters
  • string The string value to be converted to datetime format.
  • format A format string which describes how to interpret the first string input. Follows standard .NET date format syntax. A few special formats are available as well, including UNIX, UNIXMILIS, TICKS, and FILETICKS.
Examples

SYSDATETIME

Returns the current time stamp as a datetime value of the database system. It is equal to GETDATE and CURRENT_TIMESTAMP, and is always in the local timezone. Syntax
Examples

SYSUTCDATETIME

Returns the current system date and time as a UTC datetime value. It is equal to GETUTCDATE. Syntax
Examples

TIMEFROMPARTS

Returns the time value for the specified time and with the specified precision. Syntax
Parameters
  • hour The integer expression specifying the hour.
  • minute The integer expression specifying the minute.
  • seconds The integer expression specifying the seconds.
  • fractions The integer expression specifying the fractions of the second.
  • precision The integer expression specifying the precision of the fraction.
Examples

TO_DAYS

Returns the number of days since 1582-10-15 (based upon the Gregorian calendar). This will be equivalent to the MYSQL TO_DAYS function. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

WEEK

Returns the week (of the year) associated with the provided datetime. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples

YEAR

Returns the integer that specifies the year of the specified date. Syntax
Parameters
  • date The datetime string that specifies the date.
Examples