間違った日付を出力するコードの問題は何ですか?
$date = "1990-05-07"; // Y-m-d
$date1 = date("d/m/Y", strtotime($date)); // Here is fine.
$date2 = date("Y-m-d", strtotime($date1)); // Here is wrong.
echo $date2; // output: 1990-07-05
上記のコードは簡単なデモンストレーションです。正確なコードは次のとおりです: (Yii フレームワーク)
Model.php
public function afterFind()
{
if ($this->birthday)
{
$this->birthday = date("d/m/Y", strtotime($this->birthday));
}
}
public function beforeSave()
{
if ($this->birthday)
{
$this->birthday = date("Y-m-d", strtotime($this->birthday));
}
}