Reputation: 421
I have this project about enrollment system and would like to format in an abbreviated form including the time of the class. For example the schedule is 2:30-4:00 on monday, wednesday and friday. How can I format it to be like mwf 2:30-4:00 pm. I already read the Carbon documentation at http://carbon.nesbot.com/docs/ but I cannot find the format I wanted. Any help are much appreciated.
Upvotes: 0
Views: 247
Reputation: 591
Carbon cannot display a date/time range like it appears you are requesting. You would have to either work with an end time or a duration.
Assuming you are using a start time and duration:
$startTime = '16:00'; // stored in 24hr time
$duration = 90; // minutes
$carbonStartTime = Carbon::createFromFormat('H:i', $startTime);
$formattedTime = 'MWF ' . $carbonStartTime->format('g:i') . ' - ' . $carbonStartTime->addMinutes($duration)->format('g:i a');
echo $formattedTime; // MWF 4:00 - 5:30 pm
PHP Date format reference is always handy.
Upvotes: 1