如何在php中将时间格式从M-d-Y更改为Y-M-d?
我正在从calender获取M-d-Y格式的输入,但我想在将其存储在数据库中时将其转换为Y-M-d。我可以使用什么方法?试试这个:如何在php中将时间格式从M-d-Y更改为Y-M-d?,php,date,Php,Date,我正在从calender获取M-d-Y格式的输入,但我想在将其存储在数据库中时将其转换为Y-M-d。我可以使用什么方法?试试这个: $date="05-25-2014"; print(date("y-m-d",strtotime($date))); 你可以试试这个strotime是你的朋友 echo date("Y-m-d", strtotime('Dec-02-2014')); 或mysql函数,但mysql以yyyy-mm-dd格式存储日期。使用date()和strotime()类似:
$date="05-25-2014";
print(date("y-m-d",strtotime($date)));
你可以试试这个
strotime
是你的朋友
echo date("Y-m-d", strtotime('Dec-02-2014'));
或mysql函数,但mysql以yyyy-mm-dd
格式存储日期。使用date()
和strotime()
类似:
$var = date('Y-m-d', strtotime($timestring))
复制自:
确保strotime函数中使用正斜杠/和连字符-之间没有区别。引自php.net
我认为最好是用Mysql本身来做。当我们有这么多功能的时候。如下图所示:
SELECT STR_TO_DATE('Jan-31-2014', '%b-%d-%Y');
Insert into tableName `date` = STR_TO_DATE(InputVal, '%b-%d-%Y');
您可以将其用于插入查询,如下所示:
SELECT STR_TO_DATE('Jan-31-2014', '%b-%d-%Y');
Insert into tableName `date` = STR_TO_DATE(InputVal, '%b-%d-%Y');
有关更多信息:执行此操作会给我带来此错误:未定义索引:D:\xampp\htdocs\my bus ticket reservation system\myticket.php中的70-01-01,第84行答案为70-01-01