PHP code example of openpsa / ranger

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

    

openpsa / ranger example snippets



use OpenPsa\Ranger\Ranger;

$ranger = new Ranger('en');
echo $ranger->format('2013-10-05', '2013-10-20');
// Oct 5–20, 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// Oct 5 – Nov 20, 2013

$ranger = new Ranger('en_GB');
echo $ranger->format('2013-10-05', '2013-10-20');
// 5–20 Oct 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 5 Oct – 20 Nov 2013

$ranger = new Ranger('de');
echo $ranger->format('2013-10-05', '2013-10-20');
// 05.–20.10.2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 05.10.–20.11.2013


use OpenPsa\Ranger\Ranger;
use IntlDateFormatter;

$ranger = new Ranger('en');
$ranger
    ->setRangeSeparator(' and ')
    ->setDateTimeSeparator(', between ')
    ->setDateType(IntlDateFormatter::LONG)
    ->setTimeType(IntlDateFormatter::SHORT);

echo $ranger->format('2013-10-05 10:00:01', '2013-10-05 13:30:00');
// October 5, 2013, between 10:00 AM and 1:30 PM