PHP code example of shrikeh / datetime

1. Go to this page and download the library: Download shrikeh/datetime library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shrikeh / datetime example snippets




$date1 = new DateTime('+7 days');
$date2 = new DateTimeImmutable();
$date3 = new DateTime('+5 hours');
$date4 = new DateTimeImmutable('-1 hour');

$range = Range::fromDateTimes(
    $date1,
    $date2,
    $date3,
    $date4,
);

foreach ($range() as $date) {
// Will iterate as $date4, $date2, $date3, $date 1
}

$range = Range::fromDateTimes(
    new DateTimeImmutable(),
    new DateTimeImmutable('+2 years'),
    new DateTimeImmutable('+1 month'),
);

$period = $range->period();