A libary to handle dates and times separately from one another.

0.1.0 2018-07-11 05:40 UTC

This package is auto-updated.

Last update: 2023-01-23 06:33:45 UTC


A libary to handle dates and times separately from one another.

Latest Stable Version License Build Status Scrutinizer Code Quality Coverage Status


So far all the libraries around that help handling Dates and Times all extend one of PHPs DateTime-Objects.

This library tries to address that by providing two separate Objects that handle Dates and Times respectively. Internaly they do use PHPs DateTimeImmutable-Object but that's not exposed to the outside.

So now you can use a Date-Object without having to worry about the time-component and vice-versa.


This library is best installed using composer.

composer require datetime/datetime



There is a Date-Object as well as a DateInterval-Object

Easiest usage is like this:

$date = new \DateTime\Date('2018-07-05');
echo $date->format('d. m. Y');
// 05. 07. 2018
echo $date->format('jS \o\f F Y H:i:s');
// 5th of July 2018 H:i:s

Another possibility would be to use it like this:

$date = new \DateTime\Date('last wednesday of june 2018');
echo $date->format('d. m. Y');
// 27. 06. 2018

Or to use the DateInterval-Object:

$date1 = new \DateTime\Date('2018-07-05');
$date2 = new \DateTime\Date('2020-07-05');
$interval = $date1->diff($date2);

echo $interval->format('%d %m %y');
// 731 0 0


There is also a Time-Object as well as a TimeInterval-Object

Those can be used as follows:

$time = new \DateTime\Time('12:23:34');
echo $time->format('H:i:s');
// 12:23:34
echo $time->format('jS \o\f F Y H:i:s');
// jS of F Y 12:23:34