I have a date string and start time as a string too, im first combining the dates with PHP date()
object, then im parsing to a Carbon object, when I return the carbon object I get a different dateTime than the expected result, for example $combinedDt = 2021-09-28 19:33
when I return $parsed
I got 2021-09-29T00:33:00.000000Z"
which is different than the input date
$combinedDT = date('Y-m-d H:i', strtotime("$request->date $request->start_time"));
$parsed = new Carbon($combinedDT, 'America/Bogota');
return $parsed;
How can I fix this problem.
CodePudding user response:
Its natural as you are using two different timezone. You can make it same timezone inside config though or use this.
$parsed= Carbon::createFromFormat('Y-m-d H:i', $request->date)
->setTimezone('America/Bogota');
return $parsed;
CodePudding user response:
you can try this instead of creating 2 different date objects
$parsed = Carbon::createFromFormat('Y-m-d H:i', $request->date'.' '.$request->start_time"));