php - How to create a Carbon date in Laravel -


how create carbon date if have date part in following format 'd m y' , have hours , minutes in separate variables integers.

eg.

$this->start_dt  = '06 feb 2016' $this->start_hr  = '12' $this->start_min  = '00' 

currently i'm having ends adding current seconds.

carbon::createfromformat('d m y', $this->start_dt)->hour($this->start_hr)->minute($this->start_min); 

result 2016-02-06 12:00:44

is there more cleaner way create carbon date without having chain hours , minutes , set seconds 00?

maybe doesn't work:

carbon::createfromformat('d m y h:i', $this->start_dt, $this->start_hr, $this->start_min); 

* update *

manage figure out:

 carbon::createfromformat('d m y h:i:s', $this->start_dt . ' ' . $this->start_hr . ':'. $this->start_min . ':00'); 

documentation: instantiation

carbon::createfromdate($year, $month, $day, $tz); carbon::createfromtime($hour, $minute, $second, $tz); carbon::create($year, $month, $day, $hour, $minute, $second, $tz); 

documentation: fluent setters

$dt->year(1975)->month(5)->day(21)->hour(22)->minute(32)->second(5)->todatetimestring(); $dt->setdate(1975, 5, 21)->settime(22, 32, 5)->todatetimestring(); $dt->setdatetime(1975, 5, 21, 22, 32, 5)->todatetimestring(); 

solution:

carbon::createfromformat('d m y', $this->start_dt)     ->settime($this->start_hr, $this->start_min); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -