我有我的日期格式的问题,这是从SQL数据库获取的值并传递给用户的窗体,并在用户将其设置回存储到数据库格式不同时返回的值。格式日期输出差异PHP
$sql = mysql_query("SELECT * FROM $memberTable WHERE id='11' LIMIT 1"); //checking from SQL
$sqlcheck = mysql_fetch_assoc($sql); //Pass each value
$dob = strftime("%Y-%B-%d", strtotime($sqlcheck['dob']));
//format from databases 2000-10-30 into 2000-October-30
$dob = explode("-", $dob);
// break into day,month,year for form to fill in
$dob = $dob[0].'-'.$dob[1].'-'.$dob[2];
// after user fill in combine together for user to input back to databases
$dob = strftime("%Y-%m-%d", strtotime($dob));
//formatting back into databases format, 2000-October-30 into 2000-10-30
//The main problem here is the output is "2000-10-02"
我想知道为什么日值变成了02而不是30? 是我用的格式代码有问题吗? 请帮助。
仅仅因为你可以建立'strftime'的格式并不意味着'strtotime'能理解它。 – Gumbo
将2000-10-30转换为2000年10月30日之后,可以使用strftime(“%Y-%m-%d”,strtotime($ dob));.问题在这里。对。建议不要转换为2000年10月30日。然后,直接使用strftime();将显示正确的结果。 –