PHP code example of drlenux / date-helper

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

    

drlenux / date-helper example snippets


interface DateChange {
    function addDay(int $count = 1): self;
    function addMonth(int $count = 1): self;
    function addYear(int $count = 1): self;
    function addHour(int $count = 1): self;
    function addMinute(int $count = 1): self;
    function addSeconds(int $count = 1): self;

    function subDay(int $count = 1): self;
    function subMonth(int $count = 1): self;
    function subYear(int $count = 1): self;
    function subHour(int $count = 1): self;
    function subMinute(int $count = 1): self;
    function subSeconds(int $count = 1): self;
    
    function diff(DateChange $date): DateInterval|bool;
}



use DrLenux\DataHelper\DateChange; 

$date = (new DateChange('2012-12-12'))
            ->addYear()
            ->addMonth(2)
            ->subDay();

interface DateFill {
    function to(string $to)
    function from(string $from)
    function inclusiveStart(bool $status)
    function inclusiveEnd(bool $status)
    function interval(string $interval)
    function format(string $format)
    function timezone(\DateTimeZone $timezone = null)

    function fill()
    function getErrors()
}



use DrLenux\DataHelper\DateFill;

$fillArray = (new DateFill())
    ->from('2011-01-01')
    ->to('2011-01-02')
    ->interval(DateFill::INTERVAL_HOUR)
    ->fill();

/*
return [
    '2011-01-01 01:00:00',
    ...
    '2011-01-01 23:00:00'
];
 */



use DrLenux\DataHelper\DateFill;

(new DateFill())
    ->from('2011-10-09 23:59:59')
    ->to('2011-10-09 23:50:00')
    ->interval('PT2M') // every 2 minute
    ->format('H:i:s')
    ->fill(); 

/*
return [
    '23:57:59',
    '23:55:59',
    '23:53:59',
    '23:51:59'
];
*/



use DrLenux\DataHelper\DateChange;

$date1 = new DateChange('01-01-2018');
$date2 = new DateChange('01-01-2017');

$diff = $date1->diff($date2);
echo $diff->days;

/*
return 365;
*/