1. Go to this page and download the library: Download ivandelabeldad/dates 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/ */
ivandelabeldad / dates example snippets
// Time only have hour, minute and seconds
$time = Time::now();
// Date have year, month, day, season and day of week
$date = Date::now();
// DateTime have date attributes and time either
$dateTime = DateTime::now();
// FROM YEAR-MONTH-DAY HOUR-MINUTE-SECOND
$time = Time::create(12, 45, 0);
$date = Date::create(1999, 12, 31);
$dateTime = DateTime::create(1999, 12, 31, 12, 45, 0);
// FROM CURRENT TIME
$time = Time::now();
$date = Date::now();
$dateTime = DateTime::now();
// FROM TIME IN SECONDS (UNIX TIME)
$time = Time::fromUnixTime(time());
$date = Date::fromUnixTime(time());
$dateTime = DateTime::fromUnixTime(time());
$startDate = Date::create(2000, 1, 1);
$endDate = Date::create(2000, 12, 31);
// Contains every day of the year 2000
$dates = DateUtils::datesBetween($startDate, $endDate);
$list = new DateArrayList();
// ADD ONE DATE
$list->add(Date::now());
// ADD MULTIPLE DATES
$list->addAll([
$date1,
$date2,
$date3,
]);
// RETURN 4
$list->size();
// REMOVE FIRST DATE AND MOVE OTHERS TO THE BEGINNING
$list->remove(0);
// DATES SORTED FROM BEFORE TO AFTER
$list->sort(new DateNaturalComparator());
// DATES SORTED FROM AFTER TO BEFORE
$list->sort(new DateNaturalComparator(), false);
// Get only weekends in summer and spring
$filtered = DateFilter::builder($listOfDates)
->filterBySeasons([Season::SUMMER, Season::SPRING])
->filterByDaysOfWeek([DayOfWeek::SATURDAY, DayOfWeek::SUNDAY])
->build();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.