Below is a full list of the date and time units that can be used in MariaDB.
Continue readingTag: dates
Convert a Month Number to the Month Name in SQL Server (T-SQL)
You can use the T-SQL code below to convert a month number to its corresponding name in SQL Server.
This is for times where you don’t actually have the full date – when all you have is the month number. If you do have the date, then here’s how to get the month name from a date.
Continue readingGet the Short Day Name in SQL Server (T-SQL)
In SQL Server, you can use the FORMAT()
function to return the short day name from a date. FORMAT()
is a T-SQL function that enables you to format dates and numbers to a specified format.
This function returns its result as a string. Specifically, it returns it as either a nvarchar or null as the case may be.
Continue reading3 Ways to Extract the Month from a Date in SQL Server (T-SQL)
Here are three T-SQL functions that you can use to extract the month from a date in SQL Server.
Continue readingExtract the Week Number from a Date in SQL Server (T-SQL)
You can use the T-SQL function DATEPART()
to return the week number from a date in SQL Server.
By “week number” I mean the week’s number within the year of the specified date.
Continue readingReturn the ISO Week Number from a Date in SQL Server (T-SQL)
If you need to extract the ISO week number from a date in SQL Server, you can use the iso_week
argument when calling the DATEPART()
function. You can alternatively use the isowk
or isoww
arguments to do the same thing.
By “ISO week”, I’m referring to the ISO 8601 date and time standard.
Continue readingChange the Date Format For the Current Session in SQL Server
Whenever you connect to SQL Server, a bunch of default settings are applied to your session. These include the language and the date format settings.
The date format is normally determined by your default language. For example, if your default language is us_english
, then the default date format will probably be mdy
, and the first day of the week will be day 7
(Sunday).
If you change your language, you the date format will implicitly be updated accordingly.
However, you still have the option of changing the date format without changing the language. To do this, you can use SET DATEFORMAT
.
Convert a Date to Another Time Zone in SQL Server
The AT TIME ZONE
clause was introduced in SQL Server 2016 to convert a date into a datetimeoffset value in a target time zone.
This function is similar to some other T-SQL functions, such as SWITCHOFFSET()
and TODATETIMEOFFSET()
, however, the AT TIME ZONE
clause allows/(requires) you to specify the time zone offset by name, instead of an actual offset value.
This article explores how AT TIME ZONE
works, and explains its benefits when compared to the other functions mentioned.
Get the Current Time Zone of the Server in SQL Server (T-SQL)
Microsoft introduced the CURRENT_TIMEZONE()
function in SQL Server 2019 for returning the time zone of the server.
More specifically, this function “returns the name of the time zone observed by a server or an instance”.
Continue reading5 Ways to Get the Milliseconds from a Date in MongoDB
This article presents 5 ways to return the milliseconds portion from a Date object in MongoDB.
Continue reading