i just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
php string to date conversion?
Collapse
X
-
Tags: None
-
I have one way how to do it, its long but for me it works ;)Originally posted by nirmalsinghi just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
i hope it will work for u!
input is 2007-04-09 and output is 09-April-2007
php code is [php]<?php
$date = "2007-04-09";
$explodedate = explode("-", $date);
$year = $explodedate[0];
$month = $explodedate[1];
$day = $explodedate[2];
if ($month == 01) { $month1 = 'Jan'; }
if ($month == 02) { $month1 = 'Feb'; }
if ($month == 03) { $month1 = 'Mar'; }
if ($month == 04) { $month1 = 'April'; }
if ($month == 05) { $month1 = 'may'; }
if ($month == 06) { $month1 = 'Jun'; }
if ($month == 07) { $month1 = 'Jul'; }
if ($month == 08) { $month1 = 'Aug'; }
if ($month == 09) { $month1 = 'Sep'; }
if ($month == 10) { $month1 = 'Oct'; }
if ($month == 11) { $month1 = 'Nov'; }
if ($month == 12) { $month1 = 'Dec'; }
echo $day."-".$month1."-".$year;
?>[/php]
Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderator -
this might work a little faster[php]function buildDate( &$date )
{
$explodedate = explode( "-", $date );
$year = $explodedate[0];
$month = $explodedate[1];
$day = $explodedate[2];
$months = array( '01' => 'Jan' , '02' => 'Feb' , '03' => 'Mar' , '04' => 'April' , '05' => 'May' , '06' => 'June' , '07' => 'July' , '08' => 'Aug' , '09' => 'Sept' , '10' => 'Oct' , '11' => 'Nov' , '12' => 'Dec' );
foreach( $months as $key => $value ){
if ( $key == $month ){
$month = $value;
break;
}
}
echo $day.'-'.$month.'-'.$year;
}[/php]
Please encode any code within the appropriate code tags, See the Posting guidelines before you continue posting in this forum - moderatorComment
-
The fastest of them all, using the most simple solution using 2 PHP commands:[php]<?phpOriginally posted by nirmalsinghi just want to convert 2007-04-09 as 09-April-2007. how to do this?? thanx in advance.
echo date('j-F-Y',strtotime('2 007-04-09'));
?>[/php]RonaldComment
Comment