Converting between time zones in SQL Server has evolved throughout the years. Prior to SQL Server 2016, there was no simple, built-in function to handle this task. We had to use a complex, multi-step approach involving functions like SWITCHOFFSET() and TODATETIMEOFFSET(), and we had to manually account for Daylight Saving Time (DST) rules for each time zone. This method was often prone to error and required constant maintenance to keep up with changing time zone and DST regulations.
dates
How to Limit a Date Range to Just Business Days in DuckDB
DuckDB enables us to easily generate a range of dates, for example by using the generate_series() function and specifying the start date and end date. But what if you need to limit the output to just those dates that are business days?
This article provides an easy way to get that result.
Convert DDMMYYYY to DATE in SQL Server
Sometimes you might get dates in a non-standard format, such as DDMMYYYY. By “non-standard” I mean a format that SQL Server doesn’t recognize as a date. Such a format is actually a little ambiguous. Some dates presented in this format could be mistaken for another date. For example, 02082026 could be August 2, 2026, or it could be February 8, 2026 depending on which locale you’re using.
Therefore, we need to do a bit of work in order to get SQL Server to recognize it as a date. Once that’s done, it’s a simple matter of converting it to an actual DATE type.
Below are a few options for converting a DDMMYYYY string to a DATE in SQL Server.
4 Ways to Format the Current Date as MM/DD/YYYY in SQL Server
In SQL Server, we can use functions like GETDATE() to get the current date and time. There are also other functions, like CURRENT_TIMESTAMP, SYSDATETIME(), etc. These functions return values using one of the valid date/time types. For example, GETDATE() and CURRENT_TIMESTAMP return a datetime type, while SYSDATETIME() returns a datetime2(7) value.
Either way, if we want the current date to be displayed using MM/DD/YYYY format, we’ll need to do some extra work.
Fortunately SQL Server provides us with a range of options for doing this, and so we can pick the one that suits our scenario.
With that in mind, here are four ways to format the current date as MM/DD/YYYY in SQL Server.
When to Use CONVERT() vs CAST() for Date Formatting in SQL Server
When formatting dates in SQL Server you may be wondering whether to use CONVERT() or CAST(). After all, both functions allow us to convert between data types. Let’s take a look at at these two functions and figure out when to use each one.
Convert MMDDYYYY to DATE in SQL Server
Sometimes we get dates in a format that SQL Server has trouble with when we try to convert them to an actual DATE value. One example would be dates in MMDDYYYY format. While it might be easy to assume that SQL Server would be able to handle this easily, when we stop to think about it, this format is fraught with danger.
The MMDDYYYY format is ambiguous. While we might know that the first two digits are for the month, SQL Server doesn’t know this. Some countries/regions use the first two digits for the day (like DDMMYYYY). So if we get a date like, 01032025, how would SQL Server know whether it’s the first day of the third month, or the third day of the first month?
Formatting DATE as MMDDYYYY in SQL Server
In SQL Server, we have several options when it comes to formatting a DATE or DATETIME value as MMDDYYYY. The two most common functions for formatting dates like this are CONVERT() and FORMAT().
5 Functions that Extract the Month from a Date in DuckDB
Sometimes when working with SQL databases like DuckDB, we need to return the month part from a date for presentation or for further processing. DuckDB provides us with a handful of functions that can help in this regard.
In this article, we’ll look at five different functions we can use to extract the month from a date in DuckDB.
Subtract Months from a Date in DuckDB
If you find yourself in the situation where you need to subtract a number of months from a date in DuckDB, here are two options for you.
2 Ways to Get the Month Name from a Date in DuckDB
DuckDB offers a pretty good range of functions that enable us to get date parts from date or timestamp value. For example, we can extract the month part from a given date value. In most cases, this will be the month number, for example 08 or just 8.
But sometimes we might want to get the actual month name, like October for example. And other times we might just want the abbreviated month name, like Oct.
Fortunately, DuckDB’s got our back. Here are two ways to return the month name from a date or timestamp value in DuckDB.