duanlou2917
2015-07-31 09:59
浏览 1.5k

我想以yyyy-mm-dd HH:mm:ss格式获取日期

I am using oracle database in php coding now i want to get data from oracle in my table local_datatime store in 24-DEC-14 format . and using php program it's display in "2014-12-24 13:31:16"

TO_DATE('2014-12-24 13:31:16', 'YYYY-MM-DD HH:MI:SS')

Is this correct ???

I used this query not working

SELECT DISTINCT
       dri.est_driver_id,
       (dri.driver_first_name || ' ' || dri.driver_last_name) driver_name,
       erd.last_tag_status,
       veh.tag,
       rf.tag_id,
       erd.local_datetime,
       rd.reader_id,
       rf.badge_id
FROM   est_driver dri
       JOIN est_vehicle veh ON dri.est_driver_id = veh.est_driver_id
       LEFT JOIN est_rfid_tag rf ON dri.est_rfid_tag_id = rf.est_rfid_tag_id
       LEFT JOIN est_rfid_reader rd
         ON rf.est_rfid_reader_id = rd.est_rfid_reader_id
       LEFT JOIN est_tag_read erd ON rf.tag_id = erd.tag_id
WHERE  dri.est_driver_id = '211'
AND erd.local_datetime = 'TO_DATE('2014-12-24 13:31:16', 'YYYY-MM-DD HH:MI:SS')'

图片转代码服务由CSDN问答提供 功能建议

我在php编码中使用oracle数据库现在我想从我的表local_datatime存储中的oracle获取数据24- DEC-14格式。 并使用php程序显示在“2014-12-24 13:31:16”

  TO_DATE('2014-12-24 13:31:16','YYYY  -MM-DD HH:MI:SS')
   
 
 

这是正确的???

我使用此查询不起作用

  SELECT DISTINCT 
 dri.est_driver_id,
(dri.driver_first_name ||''|  | dri.driver_last_name)driver_name,
 erd.last_tag_status,
 veh.tag,
 rf.tag_id,
 erd.local_datetime,
 rd.reader_id,
 
 
f.badge_id 
FROM \ test_driver \ t \ t \ t \ t \ t \ t \ tININ \ _ 
 
 
 
 
 
 
请求 veh ON dri.est_driver_id = veh.est_driver_id 
 LEFT JOIN \ test_rfid_tag rf ON dri.est_rfid_tag_id = rf.est_rfid_tag_id 
 LEFT JOIN \ test_rfid_reader rd 
 ON rf.est_rfid_reader_id = rd.est_rfid_reader_id 
 LEFT JOIN \ test_tag_read erd ON rf.tag_id =  erd.tag_id 
WHERE dri.est_driver_id ='211'
AND erd.local_datetime ='TO_DATE('2014-12-24 13:31:16','YYYY-MM-DD HH:MI:SS')'
    
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongnu4254 2015-07-31 10:52
    已采纳

    in my table local_datatime store in 24-DEC-14 format

    No. A DATE is not stored in the format you see the way it is displayed. It is stored in 7 bytes which is Oracle's proprietary format.

    Byte    Description
    
    1       Century value but before storing it add 100 to it
    2       Year and 100 is added to it before storing
    3       Month
    4       Day of the month
    5       Hours but add 1 before storing it
    6       Minutes but add 1 before storing it
    7       Seconds but add 1 before storing it
    

    AND erd.local_datetime = 'TO_DATE('2014-12-24 13:31:16', 'YYYY-MM-DD HH:MI:SS')'

    You use single-quotation marks around a string which is not the case here. Remove the single quotes. Also, the time element seems to be HH24 format which you have missed.

    AND erd.local_datetime = TO_DATE('2014-12-24 13:31:16', 'YYYY-MM-DD HH24:MI:SS')
    

    Use TO_DATE to convert a string into date, use TO_CHAR to display a date in your desired format.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题