PHPackages                             alhames/datetime - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. alhames/datetime

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alhames/datetime
================

A simple PHP API extension for DateTime

v1.0.1(3y ago)0135MITPHPPHP ^7.4 || ^8.0

Since Dec 18Pushed 3y ago1 watchersCompare

[ Source](https://github.com/alhames/datetime)[ Packagist](https://packagist.org/packages/alhames/datetime)[ Docs](https://github.com/alhames/datetime)[ RSS](/packages/alhames-datetime/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

DateTime Extension
==================

[](#datetime-extension)

Installation
------------

[](#installation)

```
$ composer require alhames/datetime

```

```
{
    "require": {
        "alhames/datetime": "^1.0"
    }
}
```

Examples of usage
-----------------

[](#examples-of-usage)

```
use Alhames\DateTime\DT;

// If now 22 Dec 2022, 10:20:30 Europe/Moscow (+03:00)

echo dt(); // 2022-12-22T10:20:30+03:00

// Create date from string
echo dt('now');           // 2022-12-22T10:20:30+03:00
echo dt('today');         // 2022-12-22T00:00:00+03:00
echo dt('-3 days');       // 2022-12-19T10:20:30+03:00
echo dt('-3 days 02:00'); // 2022-12-19T02:00:00+03:00

// Create date from object
echo dt(new \DateTime()); // 2022-12-22T10:20:30+03:00
echo dt(dt());            // 2022-12-22T10:20:30+03:00
echo dt(new DT());        // 2022-12-22T10:20:30+03:00

// Create date from timestamp
$timestamp = mktime(11, 12, 13, 10, 20, 2030);
echo dt(0);                               // 1970-01-01T03:00:00+03:00
echo dt($timestamp);                      // 2030-10-20T11:12:13+03:00
echo dt((string) $timestamp);             // 2030-10-20T11:12:13+03:00
echo dt($timestamp - DT::YEAR * 3);       // 2027-10-21T11:12:13+03:00
echo DT::createFromTimestamp($timestamp); // 2030-10-20T11:12:13+03:00

// Create start/end of day/hour
echo dt()->getStartOfDay();   // 2022-12-22T00:00:00+03:00
echo dt()->getEndOfDay();     // 2022-12-22T23:59:59+03:00
echo dt()->getStartOfHour();  // 2022-12-22T10:00:00+03:00
echo dt()->getEndOfHour();    // 2022-12-22T10:59:59+03:00
echo DT::createStartOfDay();  // 2022-12-22T00:00:00+03:00
echo DT::createEndOfDay();    // 2022-12-22T23:59:59+03:00
echo DT::createStartOfHour(); // 2022-12-22T10:00:00+03:00
echo DT::createEndOfHour();   // 2022-12-22T10:59:59+03:00

// DT is immutable
$dt = dt();
echo $dt->getStartOfHour(); // 2022-12-22T10:00:00+03:00
echo $dt;                   // 2022-12-22T10:20:30+03:00
echo $dt->setTime(3, 15);   // 2022-12-22T03:15:00+03:00
echo $dt;                   // 2022-12-22T10:20:30+03:00

// Another examples
sleep(DT::HOUR);                  // sleep for 1 hour
usleep(DT::getMicroseconds(1.5)); // sleep for 1.5 seconds

echo json_encode(['now' => dt()]); // {"now":"2022-12-22T10:20:30+03:00"}
dt()->format(DT::FORMAT_MYSQL);    // 2022-12-22 10-20-30
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

1245d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e8bde832900f6f553e866b211a56c1a1592cc915c19378bb8cadae1e7befb799?d=identicon)[Alhames](/maintainers/Alhames)

---

Top Contributors

[![alhames](https://avatars.githubusercontent.com/u/971444?v=4)](https://github.com/alhames "alhames (14 commits)")

---

Tags

datetimephpphpdatetime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alhames-datetime/health.svg)

```
[![Health](https://phpackages.com/badges/alhames-datetime/health.svg)](https://phpackages.com/packages/alhames-datetime)
```

###  Alternatives

[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14282.3k](/packages/dater-dater)[zjkal/time-helper

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

21128.6k1](/packages/zjkal-time-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
