您的位置:程序门 -> .net技术 -> c#



表格按日期分组


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


表格按日期分组
发表于:2007-04-16 15:52:33 楼主
我从数据库里面查出一张表显示在表格控件。。表里有个字段“接受日期”,现在我想根据这个字段在表格分组显示,,大概分为   “今天,本周,上周,上月”几个时间段。就像outlook样子。。。。请问如何根据当前时间来判断这几个分类啊
发表于:2007-04-16 16:07:311楼 得分:0
在检索的时候   做个判断
case
    when   datediff(day,日期字段,getdate())=0   then   '今天 '
    when   datediff(day,日期字段,getdate())> 0   and   datediff(day,日期字段,getdate()) <=7   then   '本周 '
  when   datediff(day,日期字段,getdate())> 7   and   datediff(day,日期字段,getdate()) <=14   then   '上周 '
  when   datediff(month,日期字段,getdate())=1   then   '上月 '
...
end   as   分类
发表于:2007-04-16 16:09:042楼 得分:0
能不能在程序里面判断,不在sql语句判断啊
发表于:2007-04-16 16:22:113楼 得分:0
system.datetime.now.tostring()
system.datetime.now.adddays(-7)
发表于:2007-04-16 16:28:264楼 得分:0
这种需要最好在检索的时候判断,如果非要在程序里判断,这样

                        //dt为取出的datetime类型的数据
                        datetime   now   =   datetime.now;
                        if   ((now.day   -   dt.day)   ==   0)
                        {
                                //今天
                        }
                        else   if   ((now.day   -   dt.day)   <=   7   )
                        {
                                //本周
                        }
                        else   if   ((now.day   -   dt.day)   <=   14)
                        {
                                //上周
                        }
                        else   if   ((now.month   -   dt.month)   ==   1)
                        {
                                //上月
                        }
                        else
                        {
                                //好久以前
                        }


快速检索

最新资讯
热门点击