Carbon date necessary feature

Published on Sep 22, 2022

Today I will show some common necessary feature of carbon. Which is inherited from the PHP DateTime class.

$dt = Carbon::now();
$dtToronto = Carbon::create(2012, 1, 1, 0, 0, 0, 'America/Toronto');
$dt = Carbon::parse('2012-10-5 23:26:11.123789');

$dt->addDays(29);
$dt->addDay();
$dt->subDay();
$dt->subDays(29); 

$dt->toDateString();                          // 1975-12-25
$dt->toFormattedDateString();                 // Dec 25, 1975
$dt->toTimeString();                          // 14:15:16
$dt->toDateTimeString();                      // 1975-12-25 14:15:16
$dt->toDayDateTimeString();                   // Thu, Dec 25, 1975 2:15 PM