AsDateTime suddenly Giving Value a Year Off

I use the following

public function getSimplifiedDtCreation()
{
return \Yii::$app->formatter->asDateTime($this->dtCreation, ‘M/d/Y HH:mm’);
}

but for certain value where the date was at the end of December 2021, it is now suddenly returning the value as being in 2022? I’ve check the db and the values are saved properly, as 2021, but the asDateTime is for some reason adding a full year to it. Would anyone have any ideas?

Simply returning return $this->dtCreation; does return the proper value, but then I loose the format I was after.

Could be that tzinfo is outdated at your server.

1 Like

Is there an easy way to determine this? I’m not the server admin though and might not have the necessary permissions?

https://www.php.net/manual/en/function.timezone-version-get.php

1 Like

It’s more of the problem with Y - please avoid using it if you can because since this is “year of Week of Year” and not year as we usually want (see Formatting Dates and Times - ICU Documentation ) there might be differences between Y and y (or yyyy) at the beginning and the end of year.

1 Like

You were right on the money Bizley and I should have recognized that issue as I was previously bitten by it! I’m going through my code now to make sure I haven’t missed other instances elsewhere.

Thank you! (eventually it will sink it).

1 Like

Thank you samdark for all your support! I greatly appreciate all the help you keep provide me.