Reputation: 1451
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
Upvotes: 9
Views: 10455
Reputation: 21
use Cake\I18n\FrozenTime;
$time =new FrozenTime('2021-01-31 22:11:30');
$timex = $time->i18nFormat('yyyy-MM-dd');
echo $timex;
Upvotes: 1
Reputation: 6066
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
Upvotes: 1
Reputation: 1913
If need all over the project with specific format you can use
boostrap.php
Cake\I18n\FrozenDate::setToStringFormat('yyyy-MM-dd');
Upvotes: 0
Reputation: 51
add in App\Controller:
use Cake\I18n\Time;
Time::$defaultLocale = 'es-ES';
Time::setToStringFormat('YYYY-MM-dd');
Upvotes: 5