4 Functions that Get the Week From a Date in DuckDB

Working with dates often requires extracting specific components, such as the week number, for analysis or reporting. In DuckDB, there are multiple functions to retrieve the week from a date, each catering to different needs. This article explores four such functions, including how to calculate the ISO week—a standard defined by ISO-8601 where weeks start on Monday and the first week of the year contains the year’s first Thursday.

Continue reading

How to Format Dates in DuckDB

When working with SQL databases such as DuckDB, dates usually conform to a specific format. In particular, when we create dates in DuckDB, they must conform to the ISO 8601 format (YYYY-MM-DD). It’s the same with time (hh:mm:ss[.zzzzzz][+-TT[:tt]]) and timestamp values (YYYY-MM-DD hh:mm:ss[.zzzzzzzzz][+-TT[:tt]]).

But what if we have a requirement to present these dates or timestamps in a different format?

Fortunately, DuckDB provides us with tools to so. This article explains how to format date and timestamp values according to a specified format.

Continue reading

List of DuckDB Format Specifiers for Date Formats

In DuckDB, we can use functions like strftime() and strptime() to format date or timestamp values. These functions accept a format string that specifies how the date or timestamp should be formatted.

The format string consists of one or more format specifiers. For example, '%d/%m/%Y' is a format string that consists of three format specifiers. The output from that format specifier might look something like 05/09/2050.

Continue reading

Understanding Julian Day

Julian day is a concept you might occasionally encounter in SQL code or database operations, particularly when working with date and time functions. While it may seem esoteric at first, understanding Julian day can be incredibly useful for handling date calculations, especially in fields like astronomy, data analysis, and historical research.

This article looks at the origins, calculations, and practical applications of Julian day, including examples of converting between Julian day and other date formats in SQL.

Continue reading

How TRY_PARSE() Works in SQL Server

In SQL Server, the TRY_PARSE() function returns the result of an expression, translated to the requested data type, or NULL if the conversion fails.

Basically, it works the same as the PARSE() function, except that it returns NULL instead of an error if the cast fails.

Both functions are intended for converting string values to either date/time or number types.

Continue reading

How PARSE() Works in SQL Server

In SQL Server, the PARSE() function returns the result of an expression, translated to the requested data type.

Basically, it enables us to parse a string expression to the specified data type. It’s intended for converting string values to either date/time or number types.

The PARSE() function can be handy when attempting to convert with CAST() or CONVERT() fails. The PARSE() function is able to parse the expression, and this may result in certain values being converted that wouldn’t normally be able to be converted.

Continue reading

How to Format the Month in Roman Numerals in Oracle

Oracle Database provides us with the ability to return the month from a date using roman numerals.

For example, if the month is August, its decimal value would be 08 and it’s roman numeral equivalent would be VIII.

The way to do this is to use the RM or rm format element in your format mask. That will format the month using roman numerals in uppercase or lowercase respectively.

Specifying the date format can be done in several places.

Continue reading

How to Remove the Right Padding on the Day Name in Oracle

In Oracle Database, when using the TO_CHAR() function to return the day name from a date, padding will be appended to the day name if it’s shorter than the longest valid day name for the given language and calendar.

Well, that’s the default behaviour. However, you can change this if you wish.

To suppress this padding, all you need to do is prepend the day name format element with fm.

Continue reading

How to Return the Day Number with a Suffix in MariaDB

MariaDB includes a large collection of date and time functions that return a given date in a certain format.

One thing you can do is return the day number with the relevant “st/nd/rd/th” suffix. For example, instead of returning it as say, 10 July 2025, it’s returned as 10th July 2025.

Below is an example of adding the relevant suffix to a day number in MariaDB.

Continue reading