Ok, if all your stored dates are in this EXACT format:
YYYY-MM-DD
and zero's indicate missing values, then THIS should format that for you.
Code:
<?php
$months=array(
'invalid',
'Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'
);
function formatDate($date) {
global $months;
$split=explode('-',$date);
return (
$split[2]=='00' ? '' : $split[2].' '
).(
$split[1]=='00' ? '' : $months[(int)$split[1]].' '
).$split[0];
}
$testDates=array(
'1857-00-00',
'1914-00-00',
'1952-12-00',
'1990-01-31'
);
foreach ($testDates as $date) {
echo formatDate($date),'<br />';
}
?>
Due to the incomplete data, the built in date/time/storage functions just aren't going to cut it for you... but if you have that exact date format, this should get the job done... the above code outputs:
1857
1914
Dec 1952
31 Jan 1990
Hope this helps. Does NOT remove leading zero's from the day though.... you could probably get that to work just by changing this line:
$split[2]=='00' ? '' : $split[2].' '
to read:
$split[2]=='00' ? '' : ((int)$split[2]).' '
typecasting to integer strips out the zero.
Bookmarks