私が探していたもの(そして聞きたくなかったもの)
これが私のように怠惰な人のための基本的なphp関数です。
function formatDatabaseDate($date, $delimiter = '/')
{
// this function works only on mysql date fields,
// and takes into account partial dates.
if ($date != '' && $date != NULL)
{
$datePieces = explode('-', $date);
if (count($datePieces) == 3 &&
strlen($datePieces[0]) == 4 &&
strlen($datePieces[1]) == 2 &&
strlen($datePieces[2]) == 2)
{
$datestring = '';
$months['01'] = 'Jan';
$months['02'] = 'Feb';
$months['03'] = 'Mar';
$months['04'] = 'Apr';
$months['05'] = 'May';
$months['06'] = 'Jun';
$months['07'] = 'Jul';
$months['08'] = 'Aug';
$months['09'] = 'Sep';
$months['10'] = 'Oct';
$months['11'] = 'Nov';
$months['12'] = 'Dec';
if ($datePieces[2] != '00' && $datePieces[1] != '00')
{
$datestring = $datePieces[2] . $delimiter
. $months[$datePieces[1]] . $delimiter
. $datePieces[0];
}
else if ($datePieces[1] != '00')
{
$datestring = $months[$datePieces[1]] . $delimiter
. $datePieces[0];
}
else
{
$datestring = $datePieces[0];
}
return $datestring;
}
else
{
trigger_error('date is not in a valid mysql format');
return false;
}
}
else
{
trigger_error('empty date passed to format command');
return false;
}
}