sasori Posted January 12, 2013 Share Posted January 12, 2013 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? Link to comment https://forums.phpfreaks.com/topic/273049-how-to-properly-convert-oracle-timestamp-using-only-pure-php-without-using-oracle-functions-via-db/ Share on other sites More sharing options...
oaass Posted January 12, 2013 Share Posted January 12, 2013 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 Link to comment https://forums.phpfreaks.com/topic/273049-how-to-properly-convert-oracle-timestamp-using-only-pure-php-without-using-oracle-functions-via-db/#findComment-1405096 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. Link to comment https://forums.phpfreaks.com/topic/273049-how-to-properly-convert-oracle-timestamp-using-only-pure-php-without-using-oracle-functions-via-db/#findComment-1405142 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 Link to comment https://forums.phpfreaks.com/topic/273049-how-to-properly-convert-oracle-timestamp-using-only-pure-php-without-using-oracle-functions-via-db/#findComment-1405160 Share on other sites More sharing options...
oaass 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 Nice. That's what I love about this. I learn something new every day Link to comment https://forums.phpfreaks.com/topic/273049-how-to-properly-convert-oracle-timestamp-using-only-pure-php-without-using-oracle-functions-via-db/#findComment-1405188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.