Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp 3 giving date and time fields in frozentime object

I am using cakephp 3.2 and when i am retrieving data by find query it is giving date fields in this format

Array
(
[0] => Cake\I18n\FrozenDate Object
    (
        [date] => 2016-08-01 00:00:00
        [timezone_type] => 3
        [timezone] => UTC
    )
)

and time fields in frozentime

Cake\I18n\FrozenTime Object
(
 [date] => 2016-10-11 10:00:00
 [timezone_type] => 3
 [timezone] => UTC
)

I need a common setting or global solution for complete site. So when i fetch the data by find query from database it should give me date time in simple format without any frozendate object.

like this

Array(
 [0] => 2016-08-01
)
like image 945
aman Avatar asked Oct 11 '16 05:10

aman


2 Answers

Simply call ->format('Y-m-d') on your Cake\I18n\FrozenDate object.

There's no need for Cake\I18n\FrozenDate::setToStringFormat() or $this->Time->format()

like image 176
mehov Avatar answered Oct 19 '22 19:10

mehov


You can also use TimeHelper for formating datetime in View

Example

echo $this->Time->format(
  $YourDateTimeVariable, #Your datetime variable
  'Y-MM-d'               #Your custom datetime format
);

CakePHP TimeHelper function details is Here

like image 2
Sumon Sarker Avatar answered Oct 19 '22 18:10

Sumon Sarker