In SQL Server, you can use the YEAR()
function to return the “year” part of a date. This is returned as an integer.
Below are examples of how to use this function.
In SQL Server, you can use the YEAR()
function to return the “year” part of a date. This is returned as an integer.
Below are examples of how to use this function.
In SQL Server, you can use the MONTH()
function to return the “month” part of a date. This is returned as an integer (not the month name).
Below are examples of how to use this function.
In SQL Server, you can use the DAY()
function to return the “day” part of a date. This function returns an integer that represents the day of the month (not the day of the week).
Below are examples of how to use this function.
In SQL Server, the T-SQL SYSUTCDATETIME()
function is used to return the current UTC time (Coordinated Universal Time). UTC time is the primary time standard by which the world regulates clocks and time.
The return value of the SYSUTCDATETIME()
function is derived from the computer on which the instance of SQL Server is running. The time zone is not included, and it is returned as a datetime2 value. The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.
SYSUTCDATETIME()
does the same thing that GETUTCDATE()
does, except that it returns a higher fractional precision. As mentioned, SYSUTCDATETIME()
returns a datetime2 value, whereas the GETUTCDATE()
function returns a datetime value.
When using SQL Server, you can use the T-SQL GETUTCDATE()
function to return the current UTC time (Coordinated Universal Time). UTC time is the primary time standard by which the world regulates clocks and time.
The return value of the GETUTCDATE()
function is derived from the computer on which the instance of SQL Server is running. The time zone is not included, and it is returned as a datetime value.
In SQL Server, the transact-sql SYSDATETIMEOFFSET()
function returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. This value includes the time zone offset.
Examples of usage below.
The CURRENT_TIMESTAMP
function returns the current date and time as a datetime value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.
This function is the ANSI SQL equivalent to the T-SQL GETDATE()
function, so you can use whichever one you prefer. Note that both functions have a lower date range and a lower default fractional precision than the T-SQL SYSDATETIME()
function (which returns a datetime2(7) value).
This article provides examples of the CURRENT_TIMESTAMP
function, including how you can use it with other functions to return the value you’re interested in.
The GETDATE()
function returns the current date and time as a datetime value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.
This article provides examples of the GETDATE()
function, including how you can use it with other functions to return the value you’re interested in.
The SYSDATETIME()
function returns the current date and time as a datetime2(7) value. This value is derived from the operating system of the computer that the instance of SQL Server is running on.
This article provides examples of the SYSDATETIME()
function, including how you can use it with other functions to return the value you’re interested in.
The T-SQL TIMEFROMPARTS()
function enables you to build a time value from the various time parts. You can also specify the precision of the return value.
Below are examples of how this function works.