1. Go to this page and download the library: Download ixnode/php-date-parser 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/ */
ixnode / php-date-parser example snippets
use Ixnode\PhpDateParser\DateParser;
print (new DateParser('2023-07-01'))->formatFrom('Y-m-d H:i:s');
// 2023-07-01 00:00:00
print (new DateParser('2023-07-01'))->formatTo('Y-m-d H:i:s');
// 2023-07-01 23:59:59
print (new DateParser('today'))->formatFrom('Y-m-d H:i:s');
// 2023-07-07 00:00:00
print (new DateParser('today'))->formatTo('Y-m-d H:i:s');
// 2023-07-07 23:59:59
/* Parses given date time from timezone America/New_York; Output to timezone Europe/Berlin */
print (new DateParser('<2023-07-01', 'America/New_York'))->formatFrom('Y-m-d H:i:s', 'Europe/Berlin');
// null
/* Parses given date time from timezone America/New_York; Output to timezone Europe/Berlin */
print (new DateParser('<2023-07-01', 'America/New_York'))->formatTo('Y-m-d H:i:s', 'Europe/Berlin');
// 2023-07-01 05:59:59
/* Parses given date time from timezone America/New_York */
$dateParser = (new DateParser('2023-07-01', 'America/New_York'));
/* Sets default output to timezone Asia/Tokyo */
$dateRange = $dateParser->getDateRange('Asia/Tokyo');
print $dateRange->getFrom()?->format('Y-m-d H:i:s (e)');
// 2023-07-01 13:00:00 (Asia/Tokyo)
print $dateRange->getTo()?->format('Y-m-d H:i:s (e)');
// 2023-07-02 12:59:59 (Asia/Tokyo)
bash
composer
bash
vendor/bin/php-date-parser --version
bash
0.1.10 (2023-07-21 21:39:44) - Björn Hempel <[email protected]>