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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.