如何在mysql中获得每个对应月份的第一天?
我想获得当年每个相应月份的第一天.例如,如果用户选择2010-06-15",则查询要求从2010-06-01"而不是2010-06-15"运行.
I want to get first day of every corresponding month of current year. For example, if user selects '2010-06-15', query demands to run from '2010-06-01' instead of '2010-06-15'.
请帮助我如何计算所选日期的第一天.目前,我正在尝试使用以下 mysql 选择查询来获得满意的结果:
Please help me how to calculate first day from selected date. Currently, I am trying to get desirable using following mysql select query:
Select
DAYOFMONTH(hrm_attendanceregister.Date) >=
DAYOFMONTH(
DATE_SUB('2010-07-17', INTERVAL - DAYOFMONTH('2010-07-17') + 1 DAY
)
FROM
hrm_attendanceregister;
谢谢
推荐答案
这是您要找的:
select CAST(DATE_FORMAT(NOW() ,'%Y-%m-01') as DATE);
相关文章