PHPackages                             ashishtilara/moment - 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. ashishtilara/moment

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

ashishtilara/moment
===================

DateTime Wrapper

1.0.3(12y ago)0619MITPHPPHP &gt;=5.3.0

Since Oct 19Pushed 12y ago1 watchersCompare

[ Source](https://github.com/ashishtilara/moment.php)[ Packagist](https://packagist.org/packages/ashishtilara/moment)[ RSS](/packages/ashishtilara-moment/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (5)Used By (0)

```
                                      _           _
 _ __ ___   ___  _ __ ___   ___ _ __ | |_   _ __ | |__  _ __
| '_ ` _ \ / _ \| '_ ` _ \ / _ \ '_ \| __| | '_ \| '_ \| '_ \
| | | | | | (_) | | | | | |  __/ | | | |_ _| |_) | | | | |_) |
|_| |_| |_|\___/|_| |_| |_|\___|_| |_|\__(_) .__/|_| |_| .__/
                                           |_|         |_|
```

Intro
=====

[](#intro)

### What is moment.php?

[](#what-is-momentphp)

Date library for parsing, manipulating and formatting dates.

### Any dependencies?

[](#any-dependencies)

PHP 5.3 or later since moment.php is based on php's [DateTime Class](http://php.net/manual/en/class.datetime.php).

Install
=======

[](#install)

Below you see the easiest setup to install moment:

```
{
    "require": {
        "fightbulc/moment": "1.0.*"
    }
}
```

If you wanna add it to your existing project just use the package reference: `"fightbulc/moment": "1.0.*"`.

Quick examples
==============

[](#quick-examples)

### 1. Get a moment

[](#1-get-a-moment)

```
$m = new \Moment\Moment(); // default is "now" UTC
echo $m->format(); // e.g. 2012-10-03T10:00:00+0000

$m = new Moment('now', 'Europe/Berlin');
echo $m->format(); // e.g. 2012-10-03T12:00:00+0200
```

### 2. Custom format

[](#2-custom-format)

```
$m = new \Moment\Moment('2012-04-25T03:00:00', 'CET');
echo $m->format('l, dS F Y / H:i (e)'); // Wednesday, 25th April 2012 / 03:00 (Europe/Berlin)
```

Formats are based on PHP's [Date function](http://php.net/manual/en/function.date.php)and [DateTime class](http://www.php.net/manual/en/datetime.formats.php).

### 3. Switch timezones

[](#3-switch-timezones)

```
$m = new \Moment\Moment('2012-04-25T03:00:00', 'CET');
echo $m->setTimezone('UTC')->format(); // 2012-04-25T01:00:00+0000
```

### 4. Create a custom moment and manipulate it

[](#4-create-a-custom-moment-and-manipulate-it)

```
$m = new \Moment\Moment('2012-05-15T12:30:00', 'CET');
echo $m->add('hours', 2)->format(); // 2012-05-15T14:30:00+0200

$m = new \Moment\Moment('2012-05-15T12:30:00', 'CET');
echo $m->subtract('days', 7)->subtract('minutes', 15)->format(); // 2012-05-08T12:15:00+0200
```

### 5. Difference between dates

[](#5-difference-between-dates)

```
$m = new \Moment\Moment('2013-02-01T07:00:00');
$difference = $m->fromNow();

// or from a specific moment
$m = new \Moment\Moment('2013-02-01T07:00:00');
$difference = $m->from('2011-09-25T10:00:00');

// result comes as an array
var_dump($difference);

/* array(5) {
  ["seconds"]=> string(9) "-19630800"
  ["minutes"]=> string(7) "-327180"
  ["hours"]=> string(5) "-5453"
  ["days"]=> string(7) "-227.21"
  ["weeks"]=> string(6) "-32.46"
} */
```

Roadmap
=======

[](#roadmap)

### Date validation

[](#date-validation)

Handle invalid dates.

### Useful date calculations

[](#useful-date-calculations)

Get the period by a given date. Valid periods would be: week, month, quarter, halfyear, year.

```
$m = new \Moment\Moment();

// Get the period for the given date
$m->getPeriodByDate('2012-04-08', 'month');

// result as array
[reference] => 2012-04-08, [start] => 2012-04-01, [end] => 2012-04-30, [interval] => 04
```

Get date periods by a given interval. Valid periods would be: week, month, quarter, halfyear, year.

```
$m = new Moment();

// Get the period for the 2nd quarter of 2012
$m->getPeriodByInterval('2012', 'quarter', 2);

// result as array
[reference] => 2012-04-01, [start] => 2012-04-01, [end] => 2012-06-30, [interval] => 2
```

License
=======

[](#license)

Moment.php is freely distributable under the terms of the MIT license.

Copyright (c) 2012 Tino Ehrich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity61

Established project with proven stability

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 ~132 days

Total

3

Last Release

4738d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1509613?v=4)[Ashish Tilara](/maintainers/ashishtilara)[@ashishtilara](https://github.com/ashishtilara)

---

Tags

manipulationformattimedate

### Embed Badge

![Health badge](/badges/ashishtilara-moment/health.svg)

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

###  Alternatives

[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6239.3M51](/packages/knplabs-knp-time-bundle)[league/period

Time range API for PHP

7335.7M22](/packages/league-period)[brick/date-time

Date and time library

3623.6M94](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

20410.2M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5261.1M7](/packages/tplaner-when)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1821.1M18](/packages/consistence-consistence)

PHPackages © 2026

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