Reputation: 28030
I am using cakephp 2.5.x.
I have the following code in my controller;
$Dates = $this->Model->find('all');
echo json_encode($Dates);
$Dates
contain some dates with the default format being YYYY-mm-dd
. How can I change it such that the format becomes dd-mm-YYYY
?
Upvotes: 2
Views: 3488
Reputation: 653
$Date= $this->Date->find('all',array('fields'=>array('Date.created')));
foreach ($Date as $key => $value) {
$date['date'] = date('d-m-Y',strtotime($value['Date']['created']));
}
echo "<pre>";
print_r($date);
I have made a small demo in CakePHP and It works fine. I have written it in my controller. You should try it.
Output :
Array ( [date] => 30-09-2014 )
You can set your date format as per you requirement.
Upvotes: 4
Reputation: 18600
// You can change date format Using TimeHelper like
echo $this->Time->format('2011-08-22', '%d %m, %Y');
Output
22-08-2011
Upvotes: 1
Reputation: 29
$original_date = explode('/',$Dates);
$day= $original_date[0]; // 2014
$month = $original_date[1]; // 07
$year= $original_date[2]; // 21
$date = $day.'/'.$month.'/'.$year;
echo $date;
Upvotes: 0