Ad

Split Date Into Parts - PHP/Laravel/Carbon

- 1 answer

I'm starting to integrate carbon into my website and can't seem to be able to get the format it wants.

Carbon::create($year, $month, $day, $hour, $minute, $second, $tz);

// initial data
$day = 'today';
$time = '1100';

// i then convert them
$d = date('Y-m-d',strtotime($day));
$t = date('H:i:s',strtotime($time));

// this is what I end up with
date = "2016-01-05"
time":"11:00:00"

How can I split them with php to help me extract $year, $month, $day, $hour, $minute, $second

Ad

Answer

So based on the comments:

function convertTime($day, $time){
      $d = date('Y-m-d-H-i-s',strtotime($day." +".$time));

      $expD = explode("-", $d);

      $Year = $expD[0];
      $Month = $expD[1];
      $Day   = $expD[2];
      $Hour  = $expD[3];
      $Minute = $expD[4];
      $Second = $expD[5];

      return array($Year, $Month, $Day, $Hour, $Minute, $Second);
}
Ad
source: stackoverflow.com
Ad