Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp 3 displaying date without time

CakePHP 3: I have a database field which is a DATE (not DATETIME nor TIMESTAMP)

When I display

echo $contact->date;

It will show something like 2014. 01. 06. 0:00. How to hide hours and minutes?

I tried

print $this->Time->format($contact->date, 'Y-m-d');

but I got 2014-0-6

How to get year-month-day?

rrd

like image 959
rrd Avatar asked Oct 25 '14 09:10

rrd


3 Answers

You can directly print the date object in any custom date String format by using the inbuilt i18nFormat function.

$frozenDateObj->i18nFormat('dd-MMM-yyyy');

Use Datetime Format Syntax reference for more customization

like image 51
Irshad Khan Avatar answered Nov 18 '22 06:11

Irshad Khan


Have you tried this?

echo $contact->date->format('Y-m-d');
like image 45
conFusl Avatar answered Nov 18 '22 07:11

conFusl


add in App\Controller:

use Cake\I18n\Time;
Time::$defaultLocale = 'es-ES';
Time::setToStringFormat('YYYY-MM-dd');
like image 5
edward M. Avatar answered Nov 18 '22 07:11

edward M.