drjun1994 2015-09-03 09:47
浏览 88

将查询中的oracle日期与PHP进行比较

I want to compare dates retrieved from oracle database in php. but i don't know how to convert month name like Sep to SEP. I don't know how to convert month in capital letters. I want to convert 2015-09-01 formate to 03-SEP-15.

      //sDate: 2015-09-01 eDate: 2015-09-03

$date1=date('d-M-Y', strtotime($sDate));
$date2=date('d-M-Y', strtotime($eDate));

// CREATEDATE: 03-SEP-15 02.44.42.000000 PM

QUERY:

$stid = oci_parse($conn, "SELECT * FROM table1 WHERE CAST(CREATEDATE AS DATE)  between   '".$sDate."' AND  '".$eDate."'");

ERROR:

Warning: oci_execute(): ORA-01861: literal does not match format string
  • 写回答

2条回答 默认 最新

  • doumen5895 2015-09-03 10:02
    关注

    So you have a date string like this: '2015-09-01' and you want to convert it to '01-09-2015' to be used in a query.

    If you want to debug if the issue is in how you handle the date conversion in php try to do:

    list($year,$month,$day)=explode('-',$date);
    $months = ['','JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
    
    $date = implode('-',$day,$months[$month],$year);
    

    Then try to run the query. You don't need to take the string, convert it into a date (unix timestamp) and convert it back to a string if you just need to change the order of the elements in the date. You have to follow your approach if you want to manipulate your date adding or removing some time or stuffs like that.

    If the query is still in error and you are sure that dates in your db are stored with that pattern than the issue is in the query syntax

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示