Php 格式日期输出差异
我的日期格式有问题,它是从SQL数据库中获取的值,并传递给用户的表单,作为回报,当用户将其设置回存储到数据库中时,格式就不一样了Php 格式日期输出差异,php,Php,我的日期格式有问题,它是从SQL数据库中获取的值,并传递给用户的表单,作为回报,当用户将其设置回存储到数据库中时,格式就不一样了 $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
$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"
我想知道为什么一天的值由30变为02?
我使用的格式代码有问题吗?
请提供帮助。尝试使用
date
功能,如
echo $dob = date("Y-m-d", strtotime($dob));
最好使用like(可选)
尝试使用
date
函数,如
echo $dob = date("Y-m-d", strtotime($dob));
最好使用like(可选)
@您只是没有为
strotime()
函数设置写入日期格式,您可以这样做:-
$date='2000-October-30';
$dob = explode("-", $date);
$dob = $dob[2].'-'.$dob[1].'-'.$dob[0];
echo $dob = strftime("%Y-%m-%d", strtotime($dob));
您可以检查php日期和时间格式@只要不为
strotime()
函数设置写入日期格式,您就可以这样做:-
$date='2000-October-30';
$dob = explode("-", $date);
$dob = $dob[2].'-'.$dob[1].'-'.$dob[0];
echo $dob = strftime("%Y-%m-%d", strtotime($dob));
您可以检查php日期和时间格式如果格式为“
2013-10-30
”,则strotime方法可以正确计算日期
但当日期的格式为“2013-10-30
”时,不进行计算
当你在一起构建日期时,只需在月份上做一个子字符串,以获得月份的前3个字符,这将解决你的问题
$dob = $dob[0].'-'. substr($dob[1], 0, 3) .'-'.$dob[2];
//用户填写合并后,如果格式为“
2013-10-30
”,则strotime方法将正确计算日期,以便用户输入回数据库
但当日期的格式为“2013-10-30
”时,不进行计算
当你在一起构建日期时,只需在月份上做一个子字符串,以获得月份的前3个字符,这将解决你的问题
$dob = $dob[0].'-'. substr($dob[1], 0, 3) .'-'.$dob[2];
//用户填写后,将组合在一起以供用户输入回数据库仅仅因为您可以使用
strftime
构建格式并不意味着strotime
可以理解它。将2000-10-30转换为2000-10-30后,您可以使用strftime(%Y-%m-%d),strotime($dob));。问题就在这里。正确的。建议不要转换为2000年10月30日。然后,直接使用strftime();。将显示正确的结果。仅因为您可以使用strftime
构建格式,并不意味着strotime
可以理解它。在您将2000-10-30转换为2000-10-30后,您可以使用strftime(%Y-%m-%d),strotime($dob));。问题就在这里。正确的。建议不要转换为2000年10月30日。然后,直接使用strftime();。正确的结果会显示出来。谢谢你的答案,我现在知道我的问题了。谢谢你的答案,我现在知道我的问题了。