PHPackages                             ixnode/php-date-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ixnode/php-date-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ixnode/php-date-parser
======================

PHP Date Parser - This library parses various given date and time strings into DateTime or DateTimeImmutable classes which return the time range. Can be used e.g. excellently for command line arguments and options to make database queries with.

1.0.3(2y ago)26841MITPHPPHP ^8.2

Since Jul 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ixnode/php-date-parser)[ Packagist](https://packagist.org/packages/ixnode/php-date-parser)[ RSS](/packages/ixnode-php-date-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (19)Used By (1)

PHP Date Parser
===============

[](#php-date-parser)

[![Release](https://camo.githubusercontent.com/7091d152a878da912452fb3b41e6a3226d7e07958b4ec9cb52302013fba3fde6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f69786e6f64652f7068702d646174652d706172736572)](https://github.com/ixnode/php-date-parser/releases)[![](https://camo.githubusercontent.com/2089f2c078d231622cb172afa27fd066c1c95dc3cc209247bb41cc6852e2ce5f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f69786e6f64652f7068702d646174652d706172736572)](https://github.com/ixnode/php-date-parser/releases)[![](https://camo.githubusercontent.com/195cdb2754e9b40de6a253148a136f5c4459a8193bbce1d3bf0ff0c2d23952ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f69786e6f64652f7068702d646174652d7061727365722e737667)](https://camo.githubusercontent.com/195cdb2754e9b40de6a253148a136f5c4459a8193bbce1d3bf0ff0c2d23952ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f69786e6f64652f7068702d646174652d7061727365722e737667)[![PHP](https://camo.githubusercontent.com/9ffda6c94e9634fafbd5ff0f68f442ccb690a9b88c8613f79b9c2ec14f5e596b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d3737376262332e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535267374796c653d666c6174)](https://www.php.net/supported-versions.php)[![PHPStan](https://camo.githubusercontent.com/29fcb055286f72da2b9c961f987152d1ac26a91d6cea221174abe7e01b5b7857/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d3737376262332e7376673f7374796c653d666c6174)](https://phpstan.org/user-guide/rule-levels)[![PHPUnit](https://camo.githubusercontent.com/de101a446df383674178b80c404288664983cc6de751737d976d3df023942af9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850556e69742d556e697425323054657374732d3662396264322e7376673f7374796c653d666c6174)](https://phpunit.de)[![PHPCS](https://camo.githubusercontent.com/ee1fdc76b568e414c96c160eb608dd4680475a67d714661b70a3b3c43f6ded54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485043532d50535231322d3431366434652e7376673f7374796c653d666c6174)](https://www.php-fig.org/psr/psr-12/)[![PHPMD](https://camo.githubusercontent.com/223a2afede2bd4bf4d524b7610277838a5d75504f7087fc6c36847b81a80ab43/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048504d442d414c4c2d3336346138332e7376673f7374796c653d666c6174)](https://github.com/phpmd/phpmd)[![Rector - Instant Upgrades and Automated Refactoring](https://camo.githubusercontent.com/9c119c037099401c8a61bd1ce556a58158eb09bfe452b2d132b94500e6368714/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f526563746f722d504850253230382e322d3733613136352e7376673f7374796c653d666c6174)](https://github.com/rectorphp/rector)[![LICENSE](https://camo.githubusercontent.com/e5ea4c19422baff789692dd36ee83fc11b6dc67d211dd4a56b4c721e509e8b27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f69786e6f64652f7068702d6170692d76657273696f6e2d62756e646c65)](https://github.com/ixnode/php-api-version-bundle/blob/master/LICENSE)

> This library parses various given date and time strings into DateTime or DateTimeImmutable classes which return the time range. Can be used e.g. excellently for command line arguments and options to make database queries with.

Examples / Usage
----------------

[](#examples--usage)

```
use Ixnode\PhpDateParser\DateParser;
```

### Date parser (`UTC`)

[](#date-parser-utc)

```
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
```

### Word parser (`UTC`)

[](#word-parser-utc)

- Imagine that now is the time: `2023-07-07 12:34:56`

```
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
```

### Date parser with timezones

[](#date-parser-with-timezones)

- Input: `America/New_York`
- Output: `Europe/Berlin`

```
/* Parses given date time from timezone America/New_York; Output to timezone Europe/Berlin */
print (new DateParser('
