mlseim
09-06-2006, 03: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;
}
?>
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;
}
?>