将 php 日期转换为适合 mysql 数据库 [英] Converting php date to fit mysql database

查看:59
本文介绍了将 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屋!

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