Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select date and time from oracle date field using php date function

How to take the time from date stored as 12/25/2012 5:12:05 AM .

date('l F j, Y, g:i a',strtotime($last_login_details[FL_DATETIME]));

This above function returned time as 12:00 am which should return 5:12AM.

FL_DATETIME has datatype DATE.

On database, the value is being stored like this :

   12/25/2012 5:12:05 AM
like image 221
hsuk Avatar asked Apr 25 '26 22:04

hsuk


2 Answers

According to the docs - http://docs.oracle.com/cd/B19306_01/server.102/b14220/datatype.htm#i1847 -

For input and output of dates, the standard Oracle date format is DD-MON-YY

That is most likely why $last_login_details[FL_DATETIME] is echoing 25-DEC-12

Try changing your query using TO_CHAR()

SELECT TO_CHAR(FL_DATETIME, 'MM/DD/YYYY HH24:MI:SS A.M.') AS FL_DATETIME ...

see http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html#date format

like image 76
Sean Avatar answered Apr 28 '26 11:04

Sean


Solved my problem by :

SELECT TO_CHAR(FL_DATETIME, 'DD.MM.YYYY:HH24:MI:SS') FROM "FMS_LOG" 
like image 20
hsuk Avatar answered Apr 28 '26 12:04

hsuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!