sasori Posted January 12, 2013 Share Posted January 12, 2013 (edited) 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 January 12, 2013 by sasori Quote Link to comment Share on other sites More sharing options...
oaass Posted January 12, 2013 Share Posted January 12, 2013 (edited) 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 January 12, 2013 by oaass Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 12, 2013 Share Posted January 12, 2013 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. Quote Link to comment Share on other sites More sharing options...
salathe Posted January 12, 2013 Share Posted January 12, 2013 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 Quote Link to comment Share on other sites More sharing options...
oaass Posted January 12, 2013 Share Posted January 12, 2013 (edited) 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 January 12, 2013 by oaass Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.