将 php 日期转换为适合 mysql 数据库 [英] Converting php date to fit mysql database
本文介绍了将 php 日期转换为适合 mysql 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将dd/mm/yyyy
形式的输入日期转换为yyyy-mm-dd
格式的MySQL格式.
我试图使用 date('Ym-d', strtotime($_POST['date']))
但问题是输出总是 Ydm,
我思考是因为它认为我的第二个参数是 mm/dd/yyyy
.
I want to convert an input date in the form of dd/mm/yyyy
to the MySQL format which is yyyy-mm-dd
.
I was trying to use date('Y-m-d', strtotime($_POST['date']))
but the problem is that the output is always Y-d-m,
I think because it considers my 2nd argument to be mm/dd/yyyy
.
我该如何解决?
推荐答案
date('Y-m-d', strtotime(str_replace('/', '-', $_POST['date'])))
这篇关于将 php 日期转换为适合 mysql 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文