2个日期做比较 小于3天

今天做开发一个需求,最近3天的新闻后面加一个NEW图标 ,经过研究完成.  代码如下:

 DateTime dttt = DateTime.Now;
                   
                    //string dttt12 = dttt.ToString("yyyy-MM-dd");

                   

                    if ((DateDiff(Convert.ToDateTime(timeFormat.ToString()), dttt).Days) <= 3)

                        style1 = style1.Replace("$newimg", "<img src=images/gif-0246.gif />");
                    else
                        style1 = style1.Replace("$newimg", "");

 

里面的日期格式转换 费了些时间     不过在SQL里函数DateDiff非常好用:

use gaj
select * from dbo.j_module_article where DateDiff (day,adddate,getdate())<3

 

写上 以备以后需要.

posted @ 2012-03-01 10:39  panpeng  阅读(242)  评论(0编辑  收藏  举报