标签:mysql日期
统计日期比较:
1、当日比较 (TO_DAYS(o.order_date) = TO_DAYS(#{before_today})) 2、所传日期参数大于此日期的当周周一统计 (o.order_date >= DATE_SUB(#{before_today},INTERVAL WEEKDAY(#{before_today}) + 0 DAY) ) and ( TO_DAYS(#{before_today}) >= TO_DAYS(o.order_date) ) 3、所传日期参数大于此日期的当月1号统计 (o.order_date >= CONCAT(DATE_FORMAT(LAST_DAY(#{before_today}),‘%Y-%m-‘),‘01‘) ) and ( TO_DAYS(#{before_today}) >= TO_DAYS(o.order_date) ) 4、所传日期参数大于此日期的当季度统计 (o.order_date >= CONCAT(DATE_FORMAT(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM #{before_today}),1) + INTERVAL QUARTER(#{before_today})*3-3 MONTH),‘%Y-%m-‘),‘01‘)) and ( TO_DAYS(#{before_today}) >= TO_DAYS(o.order_date) ) 5、所传日期参数大于此日期的半年统计 (TO_DAYS(o.order_date) >= TO_DAYS(DATE_FORMAT(#{half_year_date},‘%Y-%m-%d %h:%i:%s‘)) ) 6、所传日期参数大于此日期的整年统计 (YEAR(o.order_date) = YEAR(#{before_today}))
当前week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY) 当前week的最后一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) - 5 DAY) 前一week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 8 DAY) 前一week的最后一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 2 DAY) 前两week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 15 DAY) 前两week的最后一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 9 DAY) 当前month的第一天: SELECT concat(date_format(LAST_DAY(now()),‘%Y-%m-‘),‘01‘) 当前month的最后一天: SELECT LAST_DAY(now()) 前一month的第一天: SELECT concat(date_format(LAST_DAY(now() - interval 1 month),‘%Y-%m-‘),‘01‘) 前一month的最后一天: SELECT LAST_DAY(now() - interval 1 month) 前两month的第一天: SELECT concat(date_format(LAST_DAY(now() - interval 2 month),‘%Y-%m-‘),‘01‘) 前两month的最后一天: SELECT LAST_DAY(now() - interval 2 month) 当前quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),‘%Y-%m-‘),‘01‘) 当前quarter的最后一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month) 前一quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),‘%Y-%m-‘),‘01‘) 前一quarter的最后一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month) 前两quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-9 month),‘%Y-%m-‘),‘01‘) 前两quarter的最后一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-7 month)
本文出自 “江山如画待赢归” 博客,谢绝转载!
标签:mysql日期
原文地址:http://microe.blog.51cto.com/3332651/1688145