Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

SQL Date Functions

The SQL Server provides several SQL Date Functions, which helps us to work with date and time value. For example, to get the Current date or extracting year or month from the date column, etc., you need these SQL server date functions. In this article, we will show you the available list of Date functions in SQL Server along with its description.

SQL Date Functions

The following list of tables will show you the available list of SQL Date and Time Functions

Higher-Precision SQL Date and Time Functions

The following are the high precision data and time functions in SQL Server.

Function NameSyntaxReturn Data TypeDescription
SysDateTimeSYSDATETIME()datetime2(7)It returns the date and time of the system on which the current Server instance is running.
SysDateTimeOffsetSYSDATETIMEOFFSET()datetimeoffset(7)This SQL Date and time function returns the date and time along with the time zone offset of the system on which the current SQL Server instance is running.
SysUTCDateTimeSYSUTCDATETIME()datetime2(7)This will return the date and time of the computer on which the Server instance is running. Here, the date and time returns as Coordinated Universal Time or UTC Time

Lower-Precision SQL Date and Time Functions

The list of low precision Sql Server data and time functions.

Function NameSyntaxReturn Data TypeDescription
Current_TimeStampCURRENT_TIMESTAMPdatetimeIt returns the date and time of the system on which the current Server instance is running.
GetDateGETDATE()datetimeReturns the date and time of the computer on which the Server instance is running.
GetUTCDateGETUTCDATE ()datetimeThis Date function return date and time of the system on which Server instance is running. Here, date and time returned as Coordinated Universal Time or UTC Time

SQL Date Functions to gets date and Time Parts

The following SQL Date functions help you to extract the date Parts and Time Parts from the user-specified dates.

Function NameSyntaxReturn Data TypeDescription
DateNameDATENAME (datepart, date)NVARCHARThis SQL Date function returns the specified date part from user specified date.
DatePartDATEPART (datepart, date)intReturns the specified date part from the user given date.
DAYDAY(date)intReturns the Day part of the specified date.
MonthMONTH(date)intThis Date function returns the Month part of the user specified date.
YEARYEAR(date)intIt returns the year part of the user-specified date.

SQL Date Functions to gets date and Time Values from their Parts

The below functions will return date and Time from the user-specified parts, Or you can say, constructing date and time.

Function NameSyntaxReturn DatatypeDescription
DateFromPartsDATEFROMPARTS (year, month, day)dateIt returns Date value from given parts.
DateTime2FromPartsdatetime2fromparts (year, month, day, hours, minute, seconds, fractions, precision)datetime2 (precision)Returns datetime2 value with specified precision from given parts.
DateTimeFromPartsdatetimefromparts (year, month, day, hour, minute, seconds, milliseconds)datetimereturns datetime value from given parts.
DateTimeOffsetFromPartsdatetimeoffsetfroomparts (year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision)datetime (precision)Returns datetimeoffset value with specified offsets and precision from given parts.
SmallDateTimeFromPartssmalldatetimefromparts (year, month, day, hours, minute)smalldatetimeIt returns smalldatetime value from the given parts.
TimeFromPartsTIMEFROMPARTS (hours, minute, seconds, fractions, precision)time (precision)It returns Time value with specified precision.

SQL Date Functions to get Date and Time Difference

The Following SQL date functions will help you to find the differences between two dates.

Function NameSyntaxReturn Data TypeDescription
DateDiffDATEDIFF (datepart, start_date, end_date)intThis Date and time function calculate the difference between start date and end date.
DateDiff_BigDATEDIFF_BIG (datepart, start_date, end_date)bigintSame as DATEDIFF but it return bigint data type.

SQL Date and Time Functions to modify date and Time Values

The below functions help you to alter or Modify the user-specified date.

Function NameSyntaxReturn Data TypeDescription
DateAddDATEADD(datepart, number, date)Data type of date argumentThis date function returns a new datetime value by adding user specified number.
EoMonthEOMONTH(start_date, Months_to_add)Date, or return type of the first argument.Returns the last day of the month with an optional offset.
SwitchOffsetSWITCHOFFSET (DATETIMEOFFSET, Time_Zone)datetimeoffset with a fractional precision of the first argument.It changes the time zone offset of a DATETIMEOFFSET value. Remember, it preserves the UTC value
ToDateTimeOffsetTODATETIMEOFFSET (Expression, Time_Zone)datetimeoffset with fractional precision of the first argument.This Date and time function transforms the datetime2 value into datetimeofset value.

SQL Date Functions that get or set session format

The following shown SQL Server date and time functions will change the default formats. By this, you can change the default return format of a date and time.

Function NameSyntaxReturn Data TypeDescription
@@DateFirst@@DATEFIRSTtinyintThis Date function returns the current value of the session.
Set DateFirstSET DATEFIRST specific_numberNot ApplicableYou can set the first day of a week from number 1 to 7
Set DateFormatSET DATEFORMAT specific_formatNot ApplicableYou can set the format of a date.
@@Language@@LANGUAGENot ApplicableThis Sql Date function returns the Language that currently in use.
Set LanguageSET LANGUAGE language_NameNot ApplicableYou can Set or change the default language as per your requirement.
sp_helplanguagesp_helplanguage language_NameNot ApplicableIt returns all the information about the given language, and its date formats.

Date Functions to validate date and Time Values

We can use the below-shown Date and time function to validate the given value.

Function NameSyntaxReturn Data TypeDescription
ISDATEISDATE(Expression)intIt determines whether the input expression is a valid date or time value.

Filed Under: SQL

  • Install SQL Server
  • Install SQL Management Studio
  • Uninstall Management Studio
  • Install AdventureWorks Database
  • SQL Management Studio Intro
  • Connect SQL with sqlcmd utility
  • SQL Attach Database
  • SQL Detach Database
  • SQL Restore Database
  • Restore Database using BAK
  • SQL Rename Database with Files
  • Get SQL Database Names
  • SQL Create Table
  • SQL Rename Table
  • SQL Alter Table
  • SQL Add Column
  • SQL Rename Column
  • Get SQL Table Names in a DB
  • Find SQL Table Dependencies
  • Rename SQL Table & Column
  • SQL Global & Local Temp Table
  • SQL Table Variable
  • SQL Derived Table
  • SQL DATALENGTH
  • SQL Data Types
  • DML, DDL, DCL & TCL Cmds
  • SQL Query Builder
  • SQL ALIAS
  • SQL SELECT Statement
  • SQL SELECT DISTINCT
  • SQL SELECT INTO Statement
  • SQL INSERT Statement
  • SQL INSERT INTO SELECT
  • SQL BULK INSERT or BCP
  • SQL UPDATE Statement
  • SQL UPDATE from SELECT
  • SQL DELETE Statement
  • SQL TRUNCATE Table
  • SQL CASE Statement
  • SQL MERGE Statement
  • SQL Subquery
  • SQL CTE
  • SQL PIVOT
  • SQL UNPIVOT
  • SQL Clauses Examples
  • SQL TOP Clause
  • SQL WHERE Clause
  • SQL ORDER BY Clause
  • SQL GROUP BY Clause
  • SQL HAVING Clause
  • SQL Primary Key
  • SQL Foreign Key
  • SQL Referential Integrity
  • SQL Check Constraint
  • SQL Unique Constraint
  • SQL Default Constraint
  • SQL Clustered Index
  • SQL Non Clustered Index
  • SQL Filtered Indexes
  • SQL COALESCE Function
  • SQL IS NOT NULL
  • SQL IS NULL Function
  • SQL ISNULL
  • SQL JOINS
  • SQL CROSS JOIN
  • SQL FULL JOIN
  • SQL SELF JOIN
  • SQL Outer Joins
  • SQL Cross Join Vs Inner Join
  • SQL LEFT JOIN
  • SQL RIGHT JOIN
  • SQL AND & OR Operators
  • SQL Arithmetic Operators
  • SQL BETWEEN Operator
  • SQL Comparison Operators
  • SQL LIKE
  • SQL EXCEPT
  • SQL EXISTS Operator
  • SQL NOT EXISTS Operator
  • SQL INTERSECT
  • SQL IN Operator
  • SQL NOT IN Operator
  • SQL UNION
  • SQL UNION ALL
  • SQL IF ELSE
  • SQL ELSE IF
  • SQL WHILE LOOP
  • SQL Nested While Loop
  • SQL BREAK Statement
  • SQL CONTINUE Statement
  • SQL GOTO Statement
  • SQL IIF Function
  • SQL CHOOSE Function
  • SQL Change Data Capture
  • SQL Table Partitioning
  • SQL Table Partition using SSMS
  • SQL TRY CATCH
  • SQL VIEWS
  • SQL User Defined Functions
  • SQL Alter User Defined Functions
  • SQL Stored Procedure Intro
  • Useful System Stored Procedures
  • SQL SELECT Stored Procedure
  • SQL INSERT Stored Procedure
  • SQL UPDATE Stored Procedure
  • Stored Procedure Return Values
  • Stored Procedure Output Params
  • Stored Procedure Input Params
  • Insert SP result into Temp Table
  • SQL Triggers Introduction
  • SQL AFTER INSERT Triggers
  • SQL AFTER UPDATE Triggers
  • SQL AFTER DELETE Triggers
  • SQL INSTEAD OF INSERT
  • SQL INSTEAD OF UPDATE
  • SQL INSTEAD OF DELETE
  • SQL STATIC CURSOR
  • SQL DYNAMIC CURSOR
  • SQL FORWARD_ONLY Cursor
  • SQL FAST_FORWARD CURSOR
  • SQL KEYSET CURSOR
  • SQL TRANSACTIONS
  • SQL Nested Transactions
  • SQL ACID Properties
  • Create SQL Windows Login
  • Create SQL Server Login
  • SQL Server Login Error
  • Create SQL Server Roles
  • SQL Maintenance Plan
  • Backup SQL Database
  • SQL Ranking Functions Intro
  • SQL RANK Function
  • SQL PERCENT_RANK Function
  • SQL DENSE_RANK Function
  • SQL NTILE Function
  • SQL ROW_NUMBER
  • SQL Aggregate Functions
  • SQL Date Functions
  • SQL Mathematical Functions
  • SQL String Functions
  • SQL CAST Function
  • SQL TRY CAST
  • SQL CONVERT
  • SQL TRY CONVERT
  • SQL PARSE Function
  • SQL TRY_PARSE Function
  • SQL Calculate Running Total
  • SQL Find Nth Highest Salary
  • SQL Reverse String
  • SQL FOR XML PATH
  • SQL FOR XML AUTO
  • SQL FOR XML RAW

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy