PHPackages                             proger/datefmt - 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. proger/datefmt

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

proger/datefmt
==============

Date formatting unit. Supports relative time ('1 day ago'), uses easy-to-remember format strings ('d#' for day, 'D\_\_' for its name) and supports natural localizations.

84153PHP

Since Feb 13Pushed 11y ago4 watchersCompare

[ Source](https://github.com/ProgerXP/DateFmt)[ Packagist](https://packagist.org/packages/proger/datefmt)[ RSS](/packages/proger-datefmt/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

DateFmt
=======

[](#datefmt)

**DateFmt** is an easy-to-use (mostly one method) locale-aware date formatting class supporting national date/time formats and relative time (like "1 day ago"). It focuses on easy-to-remember format strings (hello, `date()` and `strftime()`).

\[ [Full syntax &amp; API](http://proger.i-forge.net/DateFmt/cWq) \]

**Updated 16 February 2014:** fixed a number of bugs in `AGO[]`, added some comments and reformatted the code. It's also possible to call `PascalCase()` methods as if they were `camelCase()` thanks to magic `__call()`. Upgrade is fully backward-compatible, therefore highly recommended for everyone.

**Features:**

1. Basic formatting: `d#` (day), `d##` (zero-padded), `D_` ("Mon"), `D__` ("Monday"), etc.
2. Relative time: `AGO[*]` = 1 minute, 2 days ago, etc.
3. Relative-exact: `AGO[d.h]` = 1 day 3 hours ago
4. Relative-short: `AGO-SHORT[d.h]` = 1d 3h ago
5. Relative if close to now, otherwise full: `AGO[t]IF-FAR[d##my]` - outputs "3 hours ago" or if the timestamp is past last 24 hours outputs full time string ("03/23/2012")
6. Suppressed "ago/after": `AGO[*]_` = 1 day 3 hours

**Natural language features:**

1. Fractions (e.g. 0.45 hour ago) get translated into "half an hour ago"
2. Indication of time using "at": `[d#.m#.y##]AT h#:m##` - outputs "23.3.2012 at 13:23" in English or "23.3.2012 в 13:23" in Russian. Note that no change was required in the format string if spite of the different language
3. Genetive form (not used in English): Posted on `AT[D__]` = Posted on Wednesday = Добавлено в среду - compare with `Posted on D__` where it would be "Добавлено в среда" (not the correct word form)

Usage
-----

[](#usage)

```
$your_timestamp = 158399691;                // => Wednesday, 08/01/1975
$formatted = DateFmt::Format('D__, d##my', $your_timestamp, 'ru');
// You could also call DateFmt::format().
```

The first argument is the format string, the second - timestamp (`time()` if omitted), the third - language (`en` if omitted).

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

[](#installation)

### Composer

[](#composer)

Available under `proger/datefmt` at [Packagist](https://packagist.org/packages/proger/datefmt).

### Laravel 3

[](#laravel-3)

As usual, use the **Artisan**:

```
php artisan bundle:install datefmt

```

Then put this into your **application/bundles.php**:

```
'datefmt' => array(
  'autoloads' => array(
    'map' => array('DateFmt' => '(:bundle)/datefmt.php')
  )
)
```

Now whenever you refer to `DateFmt` in your code its class will be autoloaded.

Limitations
-----------

[](#limitations)

- Nested rules are unsupported: `[...]?|AGO[s-d]IF-FAR[[d#my]AT h#m]`
- Multiple **IF**'s are unsupported: `AGO[d]IF>7[..]IF>21[..]IF>...`
- Empty **IF**'s are not allowed: `AGO[h] AGO[h]IF>0[]IF>3[ (AGO[d]_)]` (this would create `11 hours ago` and `74 hours ago (2 days)`)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66214?v=4)[Volodymyr Kyrylov](/maintainers/Proger)[@proger](https://github.com/proger)

### Embed Badge

![Health badge](/badges/proger-datefmt/health.svg)

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

###  Alternatives

[roundcube/carddav

CardDAV adapter for connecting to CardDAV-enabled addressbooks

27959.0k](/packages/roundcube-carddav)[web200/magento-seo

Magento 2 Seo Module

1417.2k](/packages/web200-magento-seo)

PHPackages © 2026

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