Date and Time Functions



Date and Time Functions in SQL Server


Date and time functions in SQL server are scalar functions that perform an operation on a date and time input value and returns either a string, numeric, or date and time value.

All functions are listed below:


FunctionDescription
CURRENT_TIMESTAMPReturns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is not included.
Syntax:

CURRENT_TIMESTAMP
FunctionDescription
DATEADDReturns a new datetime value based on adding an interval to the specified date.
Syntax:

DATEADD (datepart , number, date )
FunctionDescription
DATEDIFFReturns the number of date and time boundaries crossed between two specified dates.
Syntax:

DATEDIFF ( datepart , startdate , enddate )
FunctionDescription
DATENAMEReturns a character string representing the specified datepart of the specified date.
Syntax:

DATENAME ( datepart ,date )
FunctionDescription
DATEPARTReturns an integer that represents the specified datepart of the specified date.
Syntax:

DATEPART ( datepart , date )
FunctionDescription
DAYReturns an integer representing the day datepart of the specified date.
Syntax:

DAY ( date )
FunctionDescription
GETDATEReturns the current system date and time in the SQL Server standard internal format for datetime values.
Syntax:

GETDATE ( )
FunctionDescription
GETUTCDATEReturns the datetime value representing the current UTC time (Coordinated Universal Time or Greenwich Mean Time).
Syntax:

GETUTCDATE ( )
FunctionDescription
ISDATEDetermines whether a datetime or smalldatetime input expression is a valid date or time value
Syntax:

ISDATE ( expression )
FunctionDescription
MONTHReturns an integer that represents the month part of a specified date.
Syntax:

MONTH ( date )
FunctionDescription
YEARReturns an integer that represents the year part of a specified date.

Syntax:

YEAR ( date )
FunctionDescription
SWITCHOFFSETSWITCHOFFSET changes the time zone offset of a DATETIMEOFFSET value and preserves the UTC value.
Syntax:

SWITCHOFFSET ( DATETIMEOFFSET, time_zone )
FunctionDescription
TODATETIMEOFFSETTODATETIMEOFFSET transforms a datetime2 value into a datetimeoffset value. The datetime2 value is interpreted in local time for the specified time_zone.
Syntax:

TODATETIMEOFFSET ( expression, time_zone )
FunctionDescription
SYSDATETIMEReturns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is not included.
Syntax:

SYSDATETIME ( )
FunctionDescription
SYSDATETIMEOFFSETReturns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.
Syntax:

SYSDATETIMEOFFSET ( )
FunctionDescription
SYSUTCDATETIMEReturns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The date and time is returned as UTC time (Coordinated Universal Time).
Syntax:

SYSUTCDATETIME ( )

Connection String

SQL Server Connection String Formats

posted on 2019-08-27 05:53:53 - SQL Server Tutorials


UNION

union in SQL server

posted on 2019-08-09 23:05:33 - SQL Server Tutorials


System Functions

System Functions in SQL Server

posted on 2019-08-09 06:14:33 - SQL Server Tutorials


Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials