PHP code example of activecollab / datevalue

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

    

activecollab / datevalue example snippets




namespace MyApp;

use ActiveCollab\DateValue\DateValue;

$date = new DateValue('last day of April 2017');
print $date->format('Y-m-d') . "\n";



namespace MyApp;

use ActiveCollab\DateValue\DateTimeValue;

$date_time = new DateTimeValue('last day of April 2017');
print $date_time->format('Y-m-d H:i:s') . "\n";



namespace MyApp;

use ActiveCollab\DateValue\DateTimeValue;

$date_time = (new DateTimeValue('last day of April 2017'))->endOfDay();
print $date_time->format('Y-m-d H:i:s') . "\n";



namespace MyApp;

use ActiveCollab\DateValue\DateRange;
use ActiveCollab\DateValue\DateValue;
use ActiveCollab\DateValue\DateValueInterface;

$first_day = new DateValue('first day of April 2017');
$last_day = new DateValue('last day of April 2017');

$date_range = new DateRange($first_day, $last_day);

/** @var DateValueInterface $day */
foreach ($date_range as $day) {
    $this->assertInstanceOf(DateValueInterface::class, $day);
    print $day->format('Y-m-d') . "\n"; // Prints all days from 2017-04-01 to 2017-04-30.
}



namespace MyApp;

use ActiveCollab\DateValue\DateRange\MonthDateRange;
use ActiveCollab\DateValue\DateRange\QuarterDateRange;
use ActiveCollab\DateValue\DateRange\YearDateRange;

new MonthDateRange(2017, 4); // April 2017.
new QuarterDateRange(2017, 2); // Q2 2017.
new YearDateRange(2017); // The whole 2017.