PHPackages                             y0lk/php-mysql-interval - 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. [Database &amp; ORM](/categories/database)
4. /
5. y0lk/php-mysql-interval

ActiveLibrary[Database &amp; ORM](/categories/database)

y0lk/php-mysql-interval
=======================

Convert DateInterval to MySQL temporal INTERVAL expressions

0.1(7y ago)02.8kMITPHPPHP &gt;=7.1.0

Since Nov 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Y0lk/php-mysql-interval)[ Packagist](https://packagist.org/packages/y0lk/php-mysql-interval)[ RSS](/packages/y0lk-php-mysql-interval/feed)WikiDiscussions master Synced 3d ago

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

php-mysql-interval
==================

[](#php-mysql-interval)

[![Latest Stable Version](https://camo.githubusercontent.com/796b02a249aefc50f8f5765d9f98f360fbfcf66e2021f35ce17f7736e5862036/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79306c6b2f7068702d6d7973716c2d696e74657276616c2e737667)](https://packagist.org/packages/y0lk/php-mysql-interval)[![Build Status](https://camo.githubusercontent.com/da51d735766c9456500f9a24bdaef4205ab88116576605233614b5885d582517/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f59306c6b2f7068702d6d7973716c2d696e74657276616c2e737667)](https://travis-ci.org/Y0lk/php-mysql-interval)[![Code Coverage](https://camo.githubusercontent.com/7b2001baf9b2ed38fcd33b81e231e76b17aeb9626ae96344b367ca4efcd0bc3a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f59306c6b2f7068702d6d7973716c2d696e74657276616c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Y0lk/php-mysql-interval/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ab40163cf50b10e8e7c35e589300f80b6465a42d59c8454fc3a1872cb2ebf9b5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f59306c6b2f7068702d6d7973716c2d696e74657276616c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Y0lk/php-mysql-interval/?branch=master)[![License](https://camo.githubusercontent.com/c1ae342bcce9caffee56a7c32b828b8daaa482a6602850a34050164c836e570a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f79306c6b2f7068702d6d7973716c2d696e74657276616c2e737667)](https://github.com/y0lk/php-mysql-interval/blob/master/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/91b8e5a906ceeb49c69f72dfc122082aa7b59d4410e9863b6a9fc873f5f22904/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79306c6b2f7068702d6d7973716c2d696e74657276616c2e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/y0lk/php-mysql-interval)

Tiny PHP class to convert DateInterval objects to MySQL temporal interval expressions

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

[](#installation)

Via Composer

```
$ composer require y0lk/php-mysql-interval
```

Usage
-----

[](#usage)

```
use Y0lk\MySQLInterval\MySQLInterval;

//---Example with a DateInterval create from an interval specification
echo MySQLInterval::fromDateInterval(new DateInterval("P1D"), "DAY");
//Outputs "INTERVAL 1 DAY"

//---Example using diff between 2 dates
$date1 = new DateTime("2000-01-01 05:20:11.000000");
$date2 = new DateTime("2000-01-21 12:55:33.123456");
$interval = $date1->diff($date2);

$expr = MySQLInterval::fromDateInterval($interval, "DAY_MICROSECOND");
//Ouputs "INTERVAL '20 7:35:22.123456' DAY_MICROSECOND"

//---Example using a date string with fromDateString()
echo MySQLInterval::fromDateString("300 days + 7 hours", "DAY_HOUR");
//Outputs "INTERVAL '300 7' DAY_HOUR"
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/Y0lk/php-mysql-interval/blob/master/LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

2732d ago

### Community

Maintainers

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

---

Top Contributors

[![Y0lk](https://avatars.githubusercontent.com/u/1523444?v=4)](https://github.com/Y0lk "Y0lk (6 commits)")

---

Tags

dateintervalmysqlphpmysqldateintervalperiod

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/y0lk-php-mysql-interval/health.svg)

```
[![Health](https://phpackages.com/badges/y0lk-php-mysql-interval/health.svg)](https://phpackages.com/packages/y0lk-php-mysql-interval)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

213220.4M8](/packages/carbonphp-carbon-doctrine-types)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)

PHPackages © 2026

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