Home >Database >Mysql Tutorial >How to Retrieve the First Day of Corresponding Months in MySQL?

How to Retrieve the First Day of Corresponding Months in MySQL?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-12 03:12:01295browse

How to Retrieve the First Day of Corresponding Months in MySQL?

Finding the First Day of Corresponding Months in MySQL

This issue arises when needing to retrieve the first day of each month corresponding to a specific date in the current year. For instance, if the chosen date is '2010-06-15,' the query should display results from '2010-06-01' onward, not '2010-06-15.'

To compute the first day from the chosen date, the following SQL query can be used:

select CAST(DATE_FORMAT(NOW() ,'%Y-%m-01') as DATE);

The above is the detailed content of How to Retrieve the First Day of Corresponding Months in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn