Jump to content

format Oracle TIMESTAMP using PHP


rbragg

Recommended Posts

I have an Oracle db that has a column called DETAIL_DATE with a TIMESTAMP datatype. I have successfully stored current system times there. I am trying to format the date and time to my liking. I've read a bit about to_char() but I don't want to do the formatting inside of my query. Of course, the following gives me 06-SEP-07 10.38.30.000000 AM :

 

<?php
$detailDate = ociresult($callDetails,"DETAIL_DATE");
echo $detailDate; 
?>

 

How can I format the date after fetching it using Oracle/PHP functions? I have also tried echoing:

 

<?php
echo date("M j, y @ h:i a", strtotime($detailDate) ); 
?>

 

But 06-SEP-07 10.38.30.000000 AM incorrectly turns into Sep 6, 07 @ 12:00 am. I've also tried using strftime instead of strtotime.

Link to comment
https://forums.phpfreaks.com/topic/68246-format-oracle-timestamp-using-php/
Share on other sites

Ok, I don't want to rearrange my formatting. I would like to keep the "Mon day, year @ Hr:min" format instead of the format you have and the periods. I want to keep this: Sep 7, 2007 @ 10:38 am.

 

However, I don't think the format has anything to do with why my date is not displaying correctly. No matter the formatting, I'm getting the wrong date and time.

Thanks for the link. ;) I have read this before coming to post. The The Dates and Times in PHP section would apply to me. Unfortunately, my method, like this method, is not working.  :-X

 

On an earlier page, I INSERTed sysdate as a TIMESTAMP. Now, I'm just trying to pull the stamp from the db and formatting it.

 

Even ...

<?php
echo date("M j, y @ h:i a", $detailDate);
?>

 

... gives me Dec 31, 69 @ 07:00 pm from the timestamp 06-SEP-07 12.03.31.000000 PM.

Like in my first post:

 

<?php
$detailDate = ociresult($callDetails,"DETAIL_DATE"); # retrieving from query where field = DETAIL_DATE
echo date("M j, y @ h:i a", $detailDate);
?>

 

The field in my db is a TIMESTAMP. I don't imagine you'd need my actual query.

I don't know! That's what I'm trying to find out. LOL! I get the same date each time I echo on the page. Two records that have different dates stored in the db both result in Dec 31, 69 @ 07:00 pm when I have this:

 

<?php
$detailDate = ociresult($callDetails,"DETAIL_DATE");
echo date("M j, y @ h:i a", $detailDate);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.