PHP code example of org_heigl / daterange

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

    

org_heigl / daterange example snippets



use Org_Heigl\DateRange\DateRangeFormatter

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('d.m.Y');
$dateRange->setSeparator(' - ');
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.4.2015'));
// Will print: 12.03. - 13.04.2014
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 12. - 13.03.2014


use Org_Heigl\DateRange\DateRangeFormatter

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('m/d/Y');
$dateRange->setSeparator(' - ');
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 3/12/ - 3/13/2014


use Org_Heigl\DateRange\DateRangeFormatter;
use Org_Heigl\DateRange\Filter\RemoveEverythingAfterLastDateStringFilter;

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('d.m.Y');
$dateRange->setSeparator(' - ');
$dateRange->addFilter(new RemoveEverythingAfterLastDateStringFilter(), DateRangeFormatter::FILTER_FIRST_DIFF);
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 12 - 13.03.2014