PHP code example of gamajo / daterange

1. Go to this page and download the library: Download gamajo/daterange 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/ */

    

gamajo / daterange example snippets


$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('H:i d M Y'); // 14:00 – 15:00 23 Jun 2018

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('jS M Y'); // 23rd Jun 2018

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
$dateRange->changeSeparator(' to ');
echo 'From ', $dateRange->format('H:i d M Y'); // From 14:00 to 15:00 23 Jun 2018

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18'),
    new DateTimeImmutable('2018-06-24')
);
echo $dateRange->format('d·M·Y'); //  23·· – 24·Jun·2018

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18'),
    new DateTimeImmutable('2018-06-24')
);
$dateRange->changeRemovableDelimiters('·');
echo $dateRange->format('d·M·Y'); //  23 – 24·Jun·2018