简体   繁体   中英

I want to Get Date in yyyy-mm-dd HH:mm:ss format

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')'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM