tags:

views:

99

answers:

3

How do i convert the time which I pull from a database 2009-09-27 23:58:54 to the following time using PHP Sep 27, 2009.

+7  A: 

In PHP you can use strtotime or in MySQL you can use UNIX_TIMESTAMP to get the date into a timestamp.

You can then use the date function to format it as you want:

$timestamp = strtotime($myDate);
$dateStr = date('M j, Y', $timestamp);
Greg
+11  A: 

<?php echo date('M j, Y', strtotime('2009-09-27 23:58:54')); ?>

Reinis I.
+9  A: 

If you're using MySQL then I would advise you use the MySQL date_format() function, something like this:

SELECT date_format(date, '%b %e,%Y') AS `formatted_date` FROM `table_name`;
seengee
Though not an exact answer to the question ("in PHP"), this would be preferable if, as you stipulated, the OP is using MySQL. More efficient by far.
Lucas Oman
good point, guess i figured that if he's pulling it from a database in the first place this would be a more elegant solution. since he's using php, odds are he will be on mysql too.
seengee