hsuk
hsuk

Reputation: 6860

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

Upvotes: 2

Views: 30185

Answers (3)

hsuk
hsuk

Reputation: 6860

Solved my problem by :

SELECT TO_CHAR(FL_DATETIME, 'DD.MM.YYYY:HH24:MI:SS') FROM "FMS_LOG" 

Upvotes: 3

Sean
Sean

Reputation: 12433

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

Upvotes: 8

Sebastian Frohm
Sebastian Frohm

Reputation: 417

First of all, in my opinion, you should be storing all dates as unix timestamps. This makes it lot easier for you to do searches against times, and removes any inconsistencies that may arise from date string manipulation.

Second, I tested your code; it looks to be OK from what I can tell. Echo out what you are getting in the $last_login_details[FL_DATETIME] variable. The issue may lie in the variable assignment, and not the date string manipulation.

Hope that helps!

Upvotes: 0

Related Questions