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.
views:
99answers:
3
+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
2009-10-06 21:23:49
+11
A:
<?php echo date('M j, Y', strtotime('2009-09-27 23:58:54')); ?>
Reinis I.
2009-10-06 21:24:04
+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
2009-10-06 21:24:20
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
2009-11-23 17:15:42
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
2009-11-23 17:20:24