Nurlan Nurlan - 1 year ago 86
MySQL Question

How do I get the first day of the current month?

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?

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

Or better :

select * from table_name 
where (date between  DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download