Jump to content

how to properly convert oracle timestamp using only pure PHP without using oracle functions via db?


sasori

Recommended Posts

so how to convert this oracle timestamp, without using any oracle function, just pure php fucntions to manipulate this oracle timestamp? like e.g

12-JAN-13 12.00.00.000000000 AM

if i do

echo date('F d,Y',strtotime($oracleTimeStamp));

it produces

January 01,1970

and if i do

echo strtotime($oracleTimeStamp);

it produces nothing at all

what's the proper way without using any oracle function at all, just pure php to manipulate this oracle timestamp?

Edited by sasori
Link to comment
Share on other sites

I don't know if this is the most efficient solution, and I have only tested it on the string you provided so don't trust it to be solid but it's a start and working for that string

 

$string = '12-JAN-13 12.00.00.000000000 AM';
list($date,$time,$ampm) = explode(' ', $string);
list($hour,$minute,$second) = explode('.', $time);
$second = substr($second, 0, 2);
$time = $hour . '.' . $minute . '.' . $second . '' . $ampm;
var_dump(date('F d, Y h:i:s a', strtotime($date . ' ' . $time)));

 

Hope this helps

Edited by oaass
Link to comment
Share on other sites

Why refuse to use the proper tools to do the job?

 

If there isn't a very good reason[1] for this, then you really should be using the Oracle functions for this. Not only will it save you a lot of grief, but it will also be the most efficient manner to do it.

 

[1] Of all the reasons for why not, the only truly satisfactory one would be "I don't have/cant get access to them". From my point of view. Not that I'd consider that a very good reason, but at least it's not something you can do something about. :P

Link to comment
Share on other sites

You could use DateTime::createFromFormat(), adjusting the format string as necessary for your Oracle timestamp.

 

$date = DateTime::createFromFormat('d-M-y h.i.s.u??? A', '12-JAN-13 12.00.00.000000000 AM');
echo $date->format('F d, Y');
// January 12, 2013

 

Nice. That's what I love about this. I learn something new every day :)

Edited by oaass
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.