...

Date MM-DD-YYYY ==> 24th June 1983

mlseim
09-06-2006, 02:31 PM
Converts a date in the format of: YYYY-MM-DD
to a format of (for example): 24th June 1983

Copy and Paste the function into your script.
Make the function call as shown in the example.

NOTE: You can convert any combination of date format
by altering the "list" line.

Example:
YYYY-MM-DD ...
list ($yr,$mn, $dy) = split ('-', $dt);

MM-DD-YYYY ...
list ($mn,$dy, $yr) = split ('-', $dt);


<?php
$date="1983-06-24";
echo pretty_date($date);


function pretty_date($dt){
list ($yr,$mn, $dy) = split ('-', $dt);
$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$da=intval($dy);
$x="th";
if(($da == 1)||($da == 21)||($da == 31)){$x="st";}
if(($da == 2)||($da == 22)){$x="nd";}
if(($da == 3)||($da == 23)){$x="rd";}
$pd=$da.$x." ".$months[intval($mn)]." ".$yr;
return $pd;
}

?>

marek_mar
09-06-2006, 04:22 PM
Why not just:

<?php
$date = '2006-09-06';
print date('jS F Y', strtotime($date));
?>

mlseim
09-06-2006, 04:24 PM
You're right, I just saw that.
I couldn't get it to work until I saw your example.

guelphdad
09-08-2006, 05:47 PM
and if your data is in a database then use the database function (like DATE_FORMAT in mysql) to format your dates.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum