2014-01-29 118 views
-1

我的日期格式为m-d-y。现在我想将它转换成YMD格式在PHP日期格式需要转换

<input class="form-control form-control-inline input-medium default-date-picker" size="16" type="text" name="from_date" id="from_date" value="" /> 

PHP

$from_datenew = date('Y-m-d',strtotime($_POST['from_date'])); 
+0

和http://stackoverflow.com/questions/21406665/convert-from-one-date-format-to-another-in-php/21406743#21406743 –

回答

2

使用下面的代码:

$originalDate = $_POST['from_date']; 
$newDate = date("Y-m-d", strtotime($originalDate)); 
+1

在一行中'$ newDate = date(“Ymd”,strtotime($ _ POST ['from_date'])); ' –

+0

你的回答和OP的试用版有什么区别? –

+0

@Jenz:我试过了,但没有工作 – Jazz

0
$from_datenew = date_format(
    date_create_from_format('m-d-Y', $_POST['from_date']), 
    'Y-m-d' 
); 
+0

Edakos我试过但没有工作 – Jazz

+0

我明白了。现在修正原始格式,从'm-d-y'(12-31-13)到'm-d-Y'(12-31-2013)。请现在尝试。 – Edakos