I'm pretty new to php and have a problem with the following function:
protected function convertDate($date)
{
$toExplode = $date;
$pos = strpos($date, 'T');
if ($pos !== false) {
$toExplode = substr_replace($toExplode, ' ', $pos, 1);
}
if (strpos($toExplode, '.') !== false) {
$exploded = explode('.', $toExplode);
return $exploded[0];
}
if (strpos($toExplode, '+') !== false) {
$exploded = explode('+', $toExplode);
return $exploded[0];
}
}
My inputs have these formats:
- 2019-05-26T22:01:00.000Z
- 2019-03-11 10:58:33.979+00
But I would like my output to have this format:
- 2019-03-11 10:58:33
Unfortunately, when I apply the function, it returns null for this date: 2019-04-23T16:26:59Z
I can't figure out what's wrong with my function.