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
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
Have you tried this?
echo $contact->date->format('Y-m-d');
add in App\Controller:
use Cake\I18n\Time;
Time::$defaultLocale = 'es-ES';
Time::setToStringFormat('YYYY-MM-dd');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With