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 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.
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.
In SQL Server, just as you can use T-SQL to get the month name from a date, you can also use the same methods to get the day name. By day name, I mean Monday or Tuesday for example, and not the date number or number of the day of the week (which you can also get if you need it).
Here are three ways to return the day name from a date in SQL Server using T-SQL.
When using SQL Server, you have a few different options when you need to return the month name from a date using T-SQL. By month name, I’m not talking about the month number (such as 07). I’m talking about the full name of the month (such as July).
For example, when given a date of 2018-07-01, you want July to be returned.
This article presents three ways to return the month name from a date in SQL Server using T-SQL.
Each time you create a new login in SQL Server, you have the choice of assigning a default language to that login. If you don’t do this, the login will use the default language as specified in the default language server configuration option.
This article demonstrates how to set the default language server configuration option in SQL Server, using T-SQL.
When you connect to SQL Server, usually the date format is determined by your language. The default language for a session is the language for that session’s login, unless overridden on a per-session basis by using the Open Database Connectivity (ODBC) or OLE DB APIs.
The date format setting affects the interpretation of character strings as they are converted to date values for storage in the database. It does not affect the display of date data type values that are stored in the database or the storage format.
Despite the fact that the your session’s language determines the date format, you can override the date format if required. For example, if your language is us_english
, the date format will be mdy
 (so that 07/01/2018 represents the 1st of July and not the 7th of January). You can change this so that the date format is dmy
 (or any other format) while the language remains us_english
.
You can use T-SQL to explicitly set the date format of the current session by using the SET DATEFORMAT
statement.
When using SQL Server, your current connection includes a number of options that determine things like the language, date formats, etc. These could be set at whatever the default is, but they can also be overridden during the session by using a SET
statement.
The date format affects the interpretation of character strings as they are converted to date values for storage in the database. When the language is set using SET LANGUAGE
, the date format setting is implicitly set accordingly. This can be explicitly overridden with the SET DATEFORMAT
statement.
In any case, you can find the current date format by using the DBCC USEROPTIONS
command. This command returns the SET
options that have been set for the current connection.