PHP code example of cherrypick / hammertime

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

    

cherrypick / hammertime example snippets


$date = HammerTime::createFromDate(2014, 5, 31);
$date->addMonths(1); // 2014-06-30 (with default PHP DateTime (and Carbon) it would be 2014-07-01)

$date = HammerTime::createFromDate(2012, 2, 29);
$date->addYear(1); // 2013-02-28 (with default PHP DateTime (and Carbon) it would be 2013-03-01)

$date1 = HammerTime::createFromDate(2014, 2, 1);
$date2 = HammerTime::createFromDate(2014, 3, 1);

$date1->diffInMonths($date2); // 1 (with default PHP DateTime (and Carbon) it would be 0)

$date1->isSameDate($date2);
$date1->isBefore($date2);
$date1->isBeforeOrEqual($date2);
$date1->isAfter($date2);
$date1->isAfterOrEqual($date2);

$date = HammerTime::createFromDate(2014, 11, 30, 12, 42, 42);
$date->getDay(); // 30
$date->getMonth(); // 11
$date->getYear(); // 2014
$date->getHour(); // 12
$date->getMinute(); // 42
$date->getSecond(); // 42
// and many more...

// the same applies to setters.
$date->setDay(20); // 2014-11-20
// etc..