[英]PHP date dd-mm-yyyy
I would like to fill a date in as dd-mm-yyyy but I would like to save the date as Ymd in my database. 我想以dd-mm-yyyy填写日期,但我想在数据库中将日期另存为Ymd。 What I have is this:
我所拥有的是:
Form: 形成:
$factuurDatum = new Zend_Form_Element_Text('datum');
Controller: 控制器:
$data = $addInkoopfactuur->getValues();
$data['datum'] = date("Y-m-d", strtotime($data['datum']));
But it doesn't work. 但这是行不通的。 I still get an error: '08-01-2014' and does not fit the date format 'yyyy-MM-dd'.
我仍然收到错误消息:“ 08-01-2014”,但不适合日期格式“ yyyy-MM-dd”。 How can I resolve this problem?
我该如何解决这个问题?
Use this DateTime class 使用此DateTime类
<?php
$pubDt='07-01-2014';
$date = DateTime::createFromFormat('d-m-Y', $pubDt);
echo $newPubdate = $date->format('Y-m-d');
DEMO : https://eval.in/86800 演示: https : //eval.in/86800
Did you want it? 你想要吗?
$data['datum'] = "15-10-2013";
$data['datum'] = date("Y-m-d", strtotime($data['datum']));
echo $data['datum'] ;
OUTPUT: OUTPUT:
2013-10-15
Got the problem myself! 我自己遇到了问题! the addvalidator('Date', true) should be deleted in my form!
addvalidator('Date',true)应该以我的形式删除! Because the validator will set my date as yyyy-mm-dd.
因为验证器会将我的日期设置为yyyy-mm-dd。 My question was not answered clear enough, sorry!
我的问题回答得不够清楚,对不起!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.