PHP code example of cse / helpers-date

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

    

cse / helpers-date example snippets


if (Date::isToday($date)) {
    $date = Date::changeDay($date, -7);
}
$mount = Date::diff($date, 'now', '%m');
Date::getQuarterByNumberMonth($mount);

Date::getTime('01.01.2018');
// 1514754000

Date::getTime();
Date::getTime('now');
// timestemp

Date::getTime('+1 week 2 days 4 hours 2 seconds');
// timestemp

Date::toFormat('2018-01-01');
// 01.01.2018

Date::toFormat(1514754000);
// 01.01.2018

Date::toFormat(1514754000, 'Y/m/d');
// 2018/01/01

Date::toFormat();
Date::toFormat('now');
// d.m.Y

Date::toFormat('+1 week 2 days 4 hours 2 seconds');

Date::toSQL('01.01.2018');
// 2018-01-01

Date::toSQL(1514754000);
// 2018-01-01

Date::toSQL();
Date::toSQL('now');
// Y-m-d

Date::toSQL('+1 week 2 days 4 hours 2 seconds');
// Y-m-d

Date::diff('2018-07-01', '2018-07-01');
// 0

Date::diff('2018-07-01 02:00:00', '01.01.2018 00:00:00', '%h');
// 2

Date::diff(strtotime('2018-09-02'), strtotime('2018-07-02'), '%m'));
// 2

Date::diff('31.01.2018', 1514754000, '%d/%m'));
// 30/0

Date::diff('31.01.2018');
Date::diff('31.01.2018', 'now');
// %d

Date::diff'31.01.2018', '+1 week');
// %d

Date::current();
// d.m.Y

Date::current(Date::FORMAT_SQL);
// Y-m-d

Date::extremeMonthDate('11.01.2018');
// 2018-01-31

Date::extremeMonthDate('28.02.2018', 'Y-m-01');
// 2018-02-01

Date::extremeMonthDate(strtotime('28.02.2018'), 'Y-m-01');
// 2018-02-01

Date::extremeMonthDate();
Date::extremeMonthDate('now');
// Y-m-last_mounth_day

Date::extremeMonthDate('+1 week');
// Y-m-last_mounth_day + 1 week

Date::getQuarter('31.12.2018 23:59:59');
// 4

Date::getQuarter(1514754000);
// 1

Date::getQuarter();
Date::getQuarter('now');
// quarter

Date::getQuarter('+1 week 2 days 4 hours 2 seconds');
// quarter

Date::getQuarterByNumberMonth(12);
// 4

Date::changeDay('01.01.2018', 1);
// 02.01.2018

Date::changeDay('2018-01-01', -1);
// 31.12.2017

Date::changeDay('01.01.2018', -1, Date::FORMAT_SQL);
// 2017-12-31

Date::changeDay(timestamp('01.01.2018'), -1, Date::FORMAT_SQL);
// 2017-12-31

Date::isToday('01.01.2018 00:00:00');
// false

Date::isToday(1519804800);
// false

Date::isToday('now');
// true

Date::checkDateByTimestamp((new \DateTime('now'))->format('U'));
// true

Date::setTimezone();
// UTC

Date::setTimezone('GMT');
// GMT

Date::getTimezone();
// UTC

Date::isTimezone();
// true

Date::isTimezone('GMT');
// false
bash
phpunit PATH/TO/PROJECT/tests/
bash
phpunit --configuration PATH/TO/PROJECT/phpunit.xml