Return the Start of the Month in SQLite

SQLite gives us the ability to return the date of the beginning of the month, based on a given date.

This means we can return the date of the first day of the current month, or the first day of the month based on a date that we specify.

This allows us to perform further calculations on the resulting date, like adding a given number of days to it.

Continue reading

PostgreSQL DATEADD() Equivalent

Updated 20 April 2024 to include the date_add() function.

SQL Server has its DATEADD() function that adds an interval to a date value. MySQL’s DATE_ADD() and ADDDATE() for does the same thing, as does MariaDB’s DATE_ADD() and ADDDATE(). SQLite has a DATE() function that also provides the option of adding an interval to a given date.

Prior to version 16, PostgreSQL didn’t have a DATEADD() or equivalent function. But with PostgreSQL 16 came with the introduction of the date_add() function, which allows us to add an interval to a timestamp with time zone.

We can also add and subtract values from dates with date/time operators such as + and -.

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