How SUBDATE() Works in MariaDB

In MariaDB, SUBDATE() is a built-in date and time function that subtracts an amount from a given date.

It allows you to change a date by specifying the date, the unit to subtract, and the amount to subtract. You can pass a negative amount in order to add to the date, instead of subtracting from it.

SUBDATE() also has a shortcut syntax that allows you to specify the days to subtract.

Continue reading

Calculate the Age in Years in PostgreSQL

Postgres has the age() function that returns the age in years, months, and days based on two dates.

This works fine unless you only want to return the age in years.

For example, you simply want to return a person’s age based on their birthday. You want something like 32 instead of 32 years 4 mons 67 days, which is what age() is likely to return.

Fortunately there’s an easy way to do this in PostgreSQL.

Continue reading