如何获得当月的第一天

如何获得当月的第一天

本文介绍了如何获得当月的第一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从当前月份和当天的第一天从MySQL数据库中选择数据。

I need to select data from MySQL database between the 1st day of the current month and current day.

select*from table_name
where date between "1st day of current month" and "current day"

可以有人提供这个查询的工作示例?

Can someone provide working example of this query?

推荐答案

select * from table_name
where (date between  DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), interval 30 day), interval 1 day) AND CURDATE() )

或更好:

select * from table_name
where (date between  DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() )

这篇关于如何获得当月的第一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:26