<?php
// Convert MMDDYY to YYYY-MM-DD date format to be INSERTed
// into MySQL TABLE.
// If it can't convert the data because of an error, it returns 0000-00-00.
date_default_timezone_set('America/New_York');
function date_convert($date_input) {
try {
$date = new DateTime($date_input);
$date_processed = $date->format('Y-m-d');
} catch(Exception $e) {
echo "Wrong date format $date_input" . "\n";
$date_processed = "0000-00-00";
}
return $date_processed;
}
// MMDDYY (January 1, 2000)
$TRANSACTION_DATE_MMDDYY_raw = "010100";
echo date_convert($TRANSACTION_DATE_MMDDYY_raw) . "\n";
?>
输出:2013-06-28
我预计它会返回 2000-01-01,但它会返回今天的日期。我错过了什么?我怎样才能解决这个问题?谢谢!