集团目前有月度任务采购计划,要求默认展示当月创建的所有任务,计划开始时间、结束时间,实际开始时间和结束时间,跟甘特图有点类似。
展示效果
通过Excel的条件规则对符合日期范围内的日期进行单元格颜色填充。
随着月份不同天数也会出现28、 29、30、31天不等,因此需要通过编写sql获取不同月份的天数。如以下基于MySQL数据库的sql示例,不同数据库类型需自行调整SQL。
// mysql.help_topic 是MySQL的一个内置表,内置了600多条数据,其中存在一个整形的序号字段 help_topic_id 借助此表处理处当前月的每一天数据,如11月有30条数据 select * from ( select date_sub( curdate(), interval(cast(help_topic_id as signed integer)) day ) as dates, year( date_sub( curdate(), interval(cast(help_topic_id as signed integer)) day ) ) year, month( date_sub( curdate(), interval(cast(help_topic_id as signed integer)) day ) ) month, day( date_sub( curdate(), interval(cast(help_topic_id as signed integer)) day ) ) day from mysql.help_topic where help_topic_id < day(curdate()) union all select date_add( curdate(), interval(cast(help_topic_id as signed integer)+1 ) day ) as dates, year( date_add( curdate(), interval(cast(help_topic_id as signed integer)+1 ) day ) ) year, month( date_add( curdate(), interval(cast(help_topic_id as signed integer)+1 ) day ) ) month, day( date_add( curdate(), interval(cast(help_topic_id as signed integer)+1 ) day ) ) day from mysql.help_topic where help_topic_id < day(last_day(curdate())) - day(curdate()) ) t order by dates |
查询结果如下: