步驟:從第一到第四行
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 = string.Format("select count(*) from mis.YXJC_TWEB_INFOVISITS where USER_ID={0} and VISITS_TIME>=to_date(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd') and VISITS_TIME<=to_date(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd')+0.99999", userid);
DataTable dt = DBHelper.GetDataSet(sql);
return Convert.ToInt32(dt.Rows[0][0].ToString());
}
public int Select_ZuoRiFw(int userid)//查詢會員昨天訪問量
{
string sql = string.Format("select count(*) from mis.YXJC_TWEB_INFOVISITS where USER_ID={0} and VISITS_TIME>=to_date(to_char(SYSDATE-1,'yyyy-MM-dd'),'yyyy-MM-dd') and VISITS_TIME<=to_date(to_char(SYSDATE-1,'yyyy-MM-dd'),'yyyy-MM-dd')+0.99999", userid);
DataTable dt = DBHelper.GetDataSet(sql);
return Convert.ToInt32(dt.Rows[0][0].ToString());
}