strtotime返回错误的日期 [英] strtotime returning false date

查看:108
本文介绍了strtotime返回错误的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中使用strtotime函数时遇到问题,我正在尝试将mm-dd-yyyy转换为yyyy-mm-dd。在文本框中输入日期,并在提交时将日期保存到数据库中。问题是它每次都返回错误的日期(1970-01-01),这意味着我的代码没有采用我用来存储日期的变量,我的代码是:

I have a problem with strtotime function in php, i'm trying to convert mm-dd-yyyy to yyyy-mm-dd. The date is entered on the text box and on submit it should save the date to the database. the problem is it returns a wrong date(1970-01-01) each time,which means my code isn't taking the variable i use to store the date, My code is:

//dateconvert
$submitdate = date($_POST['date']);
$date   = date("Y-m-d", strtotime($submitdate));

//storeindb
$query ="INSERT INTO ticket SET date = '$date'";
$result = mysql_query($query);

我是新手,请帮忙。

推荐答案

m / d / y或dmy格式的日期通过查看各个组件之间的分隔符来消除歧义:如果分隔符是斜杠(/ ),则假设美国的m / d / y;相反,如果分隔符是破折号(-)或点(。),则采用欧洲dmy格式。

http://php.net/manual/en/function.strtotime.php

对于mm / dd / yyyy格式,您需要使用正斜杠分隔符。

You need to use the forward slash separator for mm/dd/yyyy formats.

这篇关于strtotime返回错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆