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

ActiveLibrary

lawondyss/moment-php
====================

MomentPHP is library for parsing, manipulating and formatting dates.

v1.1(11y ago)1418.4k↓47.9%5[1 issues](https://github.com/Lawondyss/MomentPHP/issues)[2 PRs](https://github.com/Lawondyss/MomentPHP/pulls)GPL-3.0PHPPHP &gt;= 5.3.0

Since Jun 3Pushed 7y ago2 watchersCompare

[ Source](https://github.com/Lawondyss/MomentPHP)[ Packagist](https://packagist.org/packages/lawondyss/moment-php)[ Docs](https://github.com/Lawondyss/MomentPHP)[ RSS](/packages/lawondyss-moment-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

MomentPHP
=========

[](#momentphp)

MomentPHP is library for parsing, manipulating and formatting dates. It's inspired by the JavaScript library [Moment.js](http://momentjs.com/).

License
-------

[](#license)

Is freely distributable under the terms of the [GPL-3](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)) license.

Install
-------

[](#install)

MomentPHP is available on [Packagist](https://packagist.org/packages/lawondyss/moment-php), where you can get it via [Composer](http://getcomposer.org/).

File **composer.json**:

```
{
    "require": {
        "lawondyss/moment-php": "dev-master"
    }
}
```

Run in command-line:

```
php composer.phar install
```

Parse
-----

[](#parse)

### Now

[](#now)

Get the current date and time:

```
$moment = new MomentPHP\MomentPHP();
```

### String

[](#string)

Create from a string with date time. The string are acceptable same as for function `strtotime` ().

```
$string = '1980-12-07';
$string = '7 December 1980';
$string = '+1 week 2 days 4 hours 2 seconds';
$string = 'next Thursday';

$moment = new MomentPHP\MomentPHP($string);
```

### Integer

[](#integer)

Create from a integer with timestamp. The integer is a number seconds from the Unix Epoch.

```
$integer = 345061302;
$integer = time();

$moment = new MomentPHP\MomentPHP($integer);
```

### DateTime

[](#datetime)

Create from a instance of the class DateTime ():

```
$moment = new MomentPHP\MomentPHP(new DateTime());
```

### String + Format

[](#string--format)

If the string is unrecognized or confusing, you can add its format. The format are same as for method `DateTime::createFromFormat` ().

```
$string = '1980-07-12';
$format = 'Y-d-m';

$moment = new MomentPHP\MomentPHP($string, $format);
```

The format may be a field with more formats. Then use the first acceptable format.

```
$string = '1980-12-07';
$format = array('U', 'Y-m-d');

$moment = new MomentPHP\MomentPHP($string, $format);
```

### Set Timezone

[](#set-timezone)

The Timezone is set via the third parameter to the constructor. Timezone may be string from a table with [supported Timezones](http://www.php.net/manual/en/timezones.php), or instance of the class DateTimeZone ().

```
$timezone = 'Europe/Prague';
$timezone = new DateTimeZone('Europe/Prague');

$moment = new MomentPHP\MomentPHP(null, null, $timezone);
```

Display
-------

[](#display)

For examples we have:

```
$moment = new MomentPHP\MomentPHP('1980-12-07 19:21:42', null, 'Europe/Prague');
```

### Format()

[](#format)

Return formating date time. Parameter is same as for function `date` ().

```
var_dump( $moment->format('d/m/Y') ); // string(10) "07/12/1980"
```

### Timestamp()

[](#timestamp)

Return number seconds from the Unix Epoch.

```
var_dump( $moment->timestamp() ); // int(345061302)
```

### Partials from date time

[](#partials-from-date-time)

```
var_dump( $moment->seconds() ); // string(2) "42"
// it`s same as
var_dump( $moment->second() );

var_dump( $moment->minutes() ); // string(2) "21"
// it's same as
var_dump( $moment->minute() );

var_dump( $moment->hours() ); // string(2) "19"
// it's same as
var_dump( $moment->hour() );

var_dump( $moment->days() ); // string(2) "07"
// it's same as
var_dump( $moment->day() );

var_dump( $moment->months() ); // string(2) "12"
// it's same as
var_dump( $moment->month() );

var_dump( $moment->years ); // string(4) "1980"
// ti's same as
var_dump( $moment->year() );

var_dump( $moment->weeks() ); //string(2) "49"
// it's same as
var_dump( $moment->week() );

// 1 (for Monday) through 7 (for Sunday)
var_dump( $moment->dayOfWeek() ); // string(1) "7"

// starting from 1
var_dump( $moment->dayOfYear() ); // string(3) "342"

var_dump( $moment->nameOfDayShort() ); // string(3) "Sun"

var_dump( $moment->nameOfDayLong() ); // string(6) "Sunday"

var_dump( $moment->dayWithSuffix() ); // string(3) "7th"

var_dump( $moment->daysInMonth() ); // string(2) "31"

var_dump( $moment->nameOfMonthShort() ); // string(3) "Dec"

var_dump( $moment->nameOfMonthLong() ); // string(8) "December"

var_dump( $moment->hourWithSuffix() ); // string(3) "7PM"

var_dump( $moment->isoDate() ); // string(25) "1980-12-07T19:21:42+01:00"

var_dump( $moment->nameOfTimezone() ); // string(13) "Europe/Prague"

var_dump( $moment->timezoneOffset() ); // int(3600)
```

### diff()

[](#diff)

Get the difference in seconds.

```
$momentB = new MomentPHP('2000-01-01 00:00:00', 'Y-m-d H:i:s', 'Europe/Prague');
var_dump( $momentB->diff($moment) ); // int(601619898)
```

To get the difference in another unit of measurement, pass that measurement as the second argument. Acceptable units: sec, second, seconds, min, minute, minutes, hour, hours, day, days, month, months, year, years

```
var_dump( $momentB->diff($moment, 'months') ); // int(227)
```

By default return number rounded down. If you want the floating point number, pass `TRUE` as the third argument.

```
var_dump( $momentB->diff($moment, 'months', true) ); // double(227.81)
```

### from()

[](#from)

A common way of displaying time. This is sometimes called timeago or relative time.

```
$momentA = new MomentPHP('1980-12-07');
$momentB = new MomentPHP('1980-12-08');

var_dump( $momentA->from($momentB) ); // string(8) "in a day"
var_dump( $momentB->from($momentA) ); // string(9) "a day ago"
```

If you can get the value without the suffix, then set second argument as `TRUE`.

```
$momentA = new MomentPHP('1980-12-07');
$momentB = new MomentPHP('1980-12-08');

var_dump( $momentA->from($momentB, true) ); // string(5) "a day"
var_dump( $momentB->from($momentA, true) ); // string(5) "a day"
```

### fromNow()

[](#fromnow)

It's equal as `from()`, but starting time is now.

```
$moment = new MomentPHP;
$moment->add(1, 'day');

var_dump( $moment->fromNow() ); // string(8) "in a day"
```

Manipulate
----------

[](#manipulate)

### add()

[](#add)

Adds an amount of days, months, years, hours, minutes and seconds. Units is same as for method `diff()`.

```
$number = 1;
$unit = 'day';
var_dump( $moment->add($number, $unit)->days() ); // string(2) "08"
```

Adds instance of class DateInterval.

```
$interval = DateInterval('1 day');
var_dump( $moment->add($interval)->days() ); // string(2) "08"
```

Adds array with parameters for loop add(). \[unit =&gt; number\]

```
$fields = array('days' => 1, 'years' => 1);
var_dump( $moment->add($fields)->format('d|Y') ); // string(7) "08|1981"
```

### sub()

[](#sub)

It's equal as add(), bud for subtracts.

```
$number = 1;
$unit = 'day';
var_dump( $moment->sub($number, $unit)->days() ); // string(2) "06"
```

### startOf()

[](#startof)

Mutates the original moment by setting it to the start of a unit of time. Units is same as for `add()`.

```
var_dump( $moment->isoDate() ); // string(25) "1980-12-07T19:21:42+01:00"

var_dump( $moment->startOf('minutes')->isoDate() ); // string(25) "1980-12-07T19:21:00+01:00"
var_dump( $moment->startOf('hours')->isoDate() ); // string(25) "1980-12-07T19:00:00+01:00"
var_dump( $moment->startOf('days')->isoDate() ); // string(25) "1980-12-07T00:00:00+01:00"
var_dump( $moment->startOf('months')->isoDate() ); // string(25) "1980-12-01T00:00:00+01:00"
var_dump( $moment->startOf('years')->isoDate() ); // string(25) "1980-01-01T00:00:00+01:00"
```

### endOf()

[](#endof)

Mutates the original moment by setting it to the end of a unit of time. Units is same as for `add()`.

```
var_dump( $moment->isoDate() ); // string(25) "1980-12-07T19:21:42+00:00"

var_dump( $moment->endOf('minutes')->isoDate() ); // string(25) "1980-12-07T19:21:59+00:00"
var_dump( $moment->endOf('hours')->isoDate() ); // string(25) "1980-12-07T19:59:59+00:00"
var_dump( $moment->endOf('days')->isoDate() ); // string(25) "1980-12-07T23:59:59+00:00"
var_dump( $moment->endOf('months')->isoDate() ); // string(25) "1980-12-31T23:59:59+00:00"
var_dump( $moment->endOf('years')->isoDate() ); // string(25) "1980-12-31T23:59:59+00:00"
```

Query
-----

[](#query)

### isLeapYear()

[](#isleapyear)

Returns `TRUE` if that year is a leap year, and `FALSE` if it is not.

```
$moment = new MomentPHP\MomentPHP('2012', 'Y');
var_dump( $moment->isLeapYear() ); // bool(true)

$moment = new MomentPHP\MomentPHP('2013', 'Y');
var_dump( $moment->isLeapYear() ); // bool(false)
```

### isDST()

[](#isdst)

Checks if the current moment is in daylight savings time.

```
$moment = new MomentPHP\MomentPHP('06', 'm');
var_dump( $moment->isDST() ); // bool(true)

$moment = new MomentPHP\MomentPHP('12', 'm');
var_dump( $moment->isDST() ); // bool(false)
```

### isBefore()

[](#isbefore)

Check if a moment is before another moment.

```
var_dump( $moment->isBefore('1980-12-31') ); // bool(true)
```

If set unit, then beginning both dates set on the unit.

```
var_dump( $moment->isBefore('1980-12-31', 'months') ); // bool(false)
```

### isAfter()

[](#isafter)

Check if a moment is after another moment. It is the exact opposite method IsBefore().

### isSame()

[](#issame)

Check if a moment is the same as another moment.

```
var_dump( $moment->isSame('1980-12-07') ); // bool(false) because time for compare date is "00:00:00"
var_dump( $moment->startOf('days')->isSame() ); // bool(true) because time for origin date set on "00:00:00"
```

### isMomentPHP()

[](#ismomentphp)

Check if a variable is a MomentPHP object.

```
var_dump( $moment->isMomentPHP(new MomentPHP\MomentPHP) ); // bool(true)
var_dump( $moment->isMomentPHP(new DateTime) ); // bool(false)
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

4353d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f642f8a219fdaad6b73c302bfc3a623148b8eefd58ea4078cdfae1f24c47fc5?d=identicon)[Lawondyss](/maintainers/Lawondyss)

---

Top Contributors

[![Lawondyss](https://avatars.githubusercontent.com/u/272130?v=4)](https://github.com/Lawondyss "Lawondyss (54 commits)")

---

Tags

datetimetimedateparseformattingmanipulate

### Embed Badge

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

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

###  Alternatives

[moment/moment

Parse, validate, manipulate, and display dates in JavaScript.

48.1k2.1M37](/packages/moment-moment)[fightbulc/moment

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js

9693.2M10](/packages/fightbulc-moment)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[jenssegers/date

A date library to help you work with dates in different languages

1.8k11.2M80](/packages/jenssegers-date)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

177661.4M4.8k](/packages/nesbot-carbon)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

218220.4M8](/packages/carbonphp-carbon-doctrine-types)

PHPackages © 2026

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