I tried
update(['access' => Carbon::now()->format('Y/m/d H:i:s')]);
it returned Y-m-d H:i:s
I tried
update(['access' => Carbon::now()->format('Y/m/d H:i:s')]);
it returned Y-m-d H:i:s
now()->format('Y-m-d H:i:s')
You Can Format like above code simply.
<?php
// ...
use Illuminate\Support\Carbon;
//...
$now = Carbon::now()->format('Y-m-d');
The default format in mysql is Y-m-d H:i:s
, so it will save and show in the same format. If you still want to store it as Y/m/d H:i:s
, then change data type of date field to varchar.
For issue mentioned in comment:
Create date object
from string first using date_create and then use date_format
to change its format.
$date=date_create($member['access']);
echo date_format($date,"Y/m/d H:i:s");
You update this in the database and from the database, you will return only Y-m-d H:i:s(Mysql default format) so
While printing the value of access
change the format what you needed.
echo date('Y/m/d H:i:s',strtotime($member['access']));
© 2022 - 2024 — McMap. All rights reserved.
Y-m-d H:i:s
, so it will save and show in the same format. If you still want to store it asY/m/d H:i:s
, then change data type of date field to varchar. – Frog