How to use YEAR, MONTH and LAST_DAY function In MariaDB
As we have understood earlier in this article, YEAR, MONTH and LAST_DAY functions allows us to manipulate the dates in different fashions. We can make use of the functions in conjunction with CONCAT_WS function to find the relevant values. The following query uses the above functions to find the values:
SELECT id, DATE(CONCAT_WS('-', YEAR(val), MONTH(val), '01')) AS first_day, LAST_DAY(val) AS last_day
FROM test;
Output:
Explanation: In the above query, we have retrieved the respective values using the functions and then concatenated them with the ‘-‘ separator.
How to Get the First and Last Day of the Month in MariaDB?
In MariaDB, working with dates is a common task, and knowing how to manipulate them can be incredibly useful. One common requirement is to find the first and last day of the month for a given date. In this article, we’ll learn various methods like YEAR, MONTH, LAST_DAY and so on which are used to get the first and last day of the month.