格式日期dd / mm / yyyy到yyyy-mm-dd PHP [英] Format date dd/mm/yyyy to yyyy-mm-dd PHP

查看:173
本文介绍了格式日期dd / mm / yyyy到yyyy-mm-dd PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种表格,其中以英国格式输入日期,我需要将其转换为

I have a form within which a date is input in UK format, and I need to convert it to

yyyy-mm-dd

eg输入的日期是: 31/03/2013 我要转换为'2013-03-31'数据库插入。

e.g. a date entered is: 31/03/2013 which I want to convert to '2013-03-31' for database insert.

我正在使用以下这些奇怪的作品:

I'm using the following which bizarrely works only sometimes:

$dateInput = $mysqli->real_escape_string($_POST['date']);
$show_date = date('Y-m-d', strtotime($dateInput));

有没有更好的方法?

推荐答案

您可能需要使用 DateTime :: createFromFormat

$show_date = DateTime::createFromFormat('d/m/Y', $dateInput)->format('Y-m-d');

这篇关于格式日期dd / mm / yyyy到yyyy-mm-dd PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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