Oracle 如何比较两个 Datetime 类型的大小

raosuper 2012-03-02 07:45:07
ASP.NET (C#) 通过form 获得了两个输入的日期, 格式为: 03/01/2011

string from = Request.Form["txtbox_PosAuthApproDate_from"];
string to = Request.Form["txtbox_PosAuthApproDate_to"];
DateTime fromd = DateTime.ParseExact(from, "MM/dd/yyyy", null); // 转换后 fromd= 2012/3/01 0:00:00
DateTime tod = DateTime.ParseExact(to, "MM/dd/yyyy", null);

将获得的string 转换成datetime 类型 ,然后从数据库Position 表中查找 时间处于 from 和 to 直接的数据 :

sql= " select id, time from POSITION where time between "+fromd+ " and "+ to;报错

sql=" select DISTINCT POSITION_NBR , INACTIVE_EFFECTIVE_DT from POSITION where ( INACTIVE_EFFECTIVE_DT between to_date('"+fromd+ "','YYYY/MM/DD HH24:MIS') and to_date('"+to+ "' ,'YYYY/MM/DD HH24:MIS') )" ; 也报错。

求指教! 谢谢!




...全文
330 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
raosuper 2012-03-03
  • 打赏
  • 举报
回复
谢谢各位提示, 最后改成这样就对了:

sql = "select DISTINCT POSITION_NBR , INACTIVE_EFFECTIVE_DT from POSITION where INACTIVE_EFFECTIVE_DT between to_date('2010/8/14 0:00:00','yyyy/MM/dd HH24:MI:SS') and to_date('2012/3/12 0:00:00' ,'yyyy/MM/dd HH24:MI:SS') ";
我心飞翔 2012-03-02
  • 打赏
  • 举报
回复
请参考下面的代码

sql="select DISTINCT POSITION_NBR , INACTIVE_EFFECTIVE_DT from POSITION where INACTIVE_EFFECTIVE_DT between to_date(" + fromd + ", 'MM/dd/yyyy') and to_date(" + tod + " ,'MM/dd/yyyy')" ;
xpingping 2012-03-02
  • 打赏
  • 举报
回复
把读入的字符串直接用呗
sql="select DISTINCT POSITION_NBR , INACTIVE_EFFECTIVE_DT from POSITION where INACTIVE_EFFECTIVE_DT between to_date("+from+ ",'MM/dd/yyyy') 
and to_date("+to+" ,'MM/dd/yyyy')" ;
yixilan 2012-03-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 forgetsam 的回复:]
fromd= '2012/3/01 0:00:00'
'YYYY/MM/DD HH24:MIS'
自己一个字一个字对,能对得上吗?对不上当然报错。
[/Quote]
哈哈,1楼说的对啊,格式和值对不上啊。
forgetsam 2012-03-02
  • 打赏
  • 举报
回复
fromd= '2012/3/01 0:00:00'

'YYYY/MM/DD HH24:MIS'

自己一个字一个字对,能对得上吗?对不上当然报错。

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧