I’m trying to save a date in a database, I’m posting the correct value which for example is Thu Oct 13 2022 15:00:00 GMT+0300
(Eastern European Summer Time) and then, the date that gets passed to the controller converts to 2022-10-13T12:00:00.000Z
this is obviously a timezone issue, although in app.php the timezone i have set is 'timezone' => 'Europe/Athens'
which is correct and it is GMT +3, what could the issue be?
2
Answers
By default, timestamps are formatted as ‘Y-m-d H:i:s’. If you need to customize the timestamp format, set the $dateFormat property on your model. This property determines how date attributes are stored in the database, as well as their format when the model is serialized to an array or JSON. Please check below example And your date format may be "E MMM d yyyy HH:mm:ss Z"
by default, the
timestamps
table in your database will have an ISO_8601 format, which you see has Z at the end which mean Zero Hour Format or Zulu Time (UTC)so the date you pass which is
Thu Oct 13 2022 15:00:00 GMT+0300
is equal to2022-10-13T12:00:00.000Z
in UTC format.you can easily convert the date to any format you want when parsing on the front-end, or you can do attribute casting