I was trying to format a date and was using
\Yii::$app->formatter->asDate($model->StartDt,‘M/d/Y’)
but as of the 28th of December, it started displaying the wrong year. Instead of 2020, it was displaying 2021.
I’ve fixed it by switching to
\Yii::$app->formatter->asDateTime($model->StartDt, ‘php:m/d/Y’)
but I’m trying to understand the why behind the issue and learn something.
after consulting the documentation
https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter#asDate()-detail
http://userguide.icu-project.org/formatparse/datetime
I see that Y -> year of “Week of Year” whereas y or yyyy -> year, but do not understand the difference. I haven’t been able to test using y and assume it would fix the issue, but would like to understand what ‘year of “Week of Year”’ is exactly. Can anyone enlighten me on this?
Thank you.