Home >Database >Mysql Tutorial >How to Find the First Day of the Month for a Given Date in MySQL?
Query to Retrieve the First Day of Each Month corresponding to a Given Date
To obtain the first day of each month corresponding to a specified date, we can utilize MySQL's built-in date manipulation functions.
Query Formulation:
To determine the first day of the month corresponding to a given date, we can apply the following query:
SELECT CAST(DATE_FORMAT(DATE_SUB(?, INTERVAL DAYOFMONTH(?) - 1 DAY), '%Y-%m-01') AS DATE);
where:
Query Explanation:
To illustrate the query's functionality:
The above is the detailed content of How to Find the First Day of the Month for a Given Date in MySQL?. For more information, please follow other related articles on the PHP Chinese website!