I have a table in database named USERSHIFTS
and it has two TIME
type columns along with other columns first one is it start_time
and second one is end_time
and both have TIME datatype
. i am not allowed to change these columns types to datetime or timestamp
. And also not allowed to create another column in table. Now my task is to display time that has been stored in start_time
and end_time
column according to user timezone
for example UTC
timezone
user should be able to time according to UTC
timezone and Other timezone user should also be able to see this time according to his timezone .
Now question is how should i store time in database and in which timezone i should store time. And Final question is how should i display time according to different timezones.
i tried following code but you can see i have to deal with date in order to do this. And i dont want date .
$s_time=date('Y-m-d '.$shift->start_time.'');
$start_time = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $s_time, 'UTC');
$e_time=date('Y-m-d '.$shift->end_time.'');
$end_time = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $e_time, 'UTC');
CodePudding user response:
$start_time = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $shift->start_time, 'UTC')->format('Y-m-d H:i:s');
$end_time = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $shift->end_time, 'UTC')->format('Y-m-d H:i:s');
CodePudding user response:
$start_time = \Carbon\Carbon::createFromFormat('H:i:s', $shift->start_time, 'UTC');
$end_time = \Carbon\Carbon::createFromFormat('H:i:s', $shift->end_time, 'UTC');