sql获取指定时间范围数据
来源:未知 责任编辑:智问网络 发表时间:2013-11-08 08:49 点击:次
以下分别为获取本天、本周、本月数据需要的where条件,其中publishDate为数据库里面存储的日期字段
此代码是在查询oracle数据库的.net 代码
[csharp] view plaincopy
DateTime today = DateTime.Now;
whereDay = string.Format("to_char(publishDate,'yyyy-mm-dd') ='{0}' ",
today.ToString("yyyy-MM-dd")
);
whereWeek = string.Format("to_char(publishDate,'yyyy-mm-dd') >='{0}' and to_char(publishDate,'yyyy-mm-dd')<='{1}' ",
today.AddDays(0 - (int)today.DayOfWeek).ToString("yyyy-MM-dd"),
today.ToString("yyyy-MM-dd")
);
whereMonth = string.Format("to_char(publishDate,'yyyy-mm-dd') >='{0}' and to_char(publishDate,'yyyy-mm-dd')<='{1}' ",
today.ToString("yyyy-MM-00"),
today.ToString("yyyy-MM-dd")
);
摘自 robot的学习日志
此代码是在查询oracle数据库的.net 代码
[csharp] view plaincopy
DateTime today = DateTime.Now;
whereDay = string.Format("to_char(publishDate,'yyyy-mm-dd') ='{0}' ",
today.ToString("yyyy-MM-dd")
);
whereWeek = string.Format("to_char(publishDate,'yyyy-mm-dd') >='{0}' and to_char(publishDate,'yyyy-mm-dd')<='{1}' ",
today.AddDays(0 - (int)today.DayOfWeek).ToString("yyyy-MM-dd"),
today.ToString("yyyy-MM-dd")
);
whereMonth = string.Format("to_char(publishDate,'yyyy-mm-dd') >='{0}' and to_char(publishDate,'yyyy-mm-dd')<='{1}' ",
today.ToString("yyyy-MM-00"),
today.ToString("yyyy-MM-dd")
);
摘自 robot的学习日志
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>