步骤:从第一到第四行
SELECT SYSDATE FROM DUAL; //获取系统当前时间
SELECT to_char(SYSDATE,'yyyyMMdd') FROM DUAL; //格式化时间
SELECT to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd') FROM DUAL; //获取到当天的0:00分
SELECT to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd')+0.99999 FROM DUAL; //获取当天的59:59秒
我在项目开发中用到的实际例子:
SELECT * FROM TERMINAL_ORDER_HEAD
where LAST_UPDATED_TIME
between to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd')
AND to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd')+0.99999;
to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd')+18/24 当天的16:00
to_date(to_char(SYSDATE,'yyyyMMdd'),'yyyyMMdd')+24/24 明天的00:00
(注意:一定要是5位9,不信你少打两个9试试。呵呵,就不是59分59秒了。)
实例:
public int Select_JinRiFw(int userid)//查询会员今日访问量
{
string sql &#61; string.Format("select count(*) from mis.YXJC_TWEB_INFOVISITS where USER_ID&#61;{0} and VISITS_TIME>&#61;to_date(to_char(SYSDATE,&#39;yyyy-MM-dd&#39;),&#39;yyyy-MM-dd&#39;) and VISITS_TIME<&#61;to_date(to_char(SYSDATE,&#39;yyyy-MM-dd&#39;),&#39;yyyy-MM-dd&#39;)&#43;0.99999", userid);
DataTable dt &#61; DBHelper.GetDataSet(sql);
return Convert.ToInt32(dt.Rows[0][0].ToString());
}
public int Select_ZuoRiFw(int userid)//查询会员昨天访问量
{
string sql &#61; string.Format("select count(*) from mis.YXJC_TWEB_INFOVISITS where USER_ID&#61;{0} and VISITS_TIME>&#61;to_date(to_char(SYSDATE-1,&#39;yyyy-MM-dd&#39;),&#39;yyyy-MM-dd&#39;) and VISITS_TIME<&#61;to_date(to_char(SYSDATE-1,&#39;yyyy-MM-dd&#39;),&#39;yyyy-MM-dd&#39;)&#43;0.99999", userid); DataTable dt &#61; DBHelper.GetDataSet(sql); return Convert.ToInt32(dt.Rows[0][0].ToString()); }