{"id":22747152,"url":"https://github.com/cs-eliseev/helpers-date","last_synced_at":"2025-04-14T11:33:46.686Z","repository":{"id":56959759,"uuid":"168916618","full_name":"cs-eliseev/helpers-date","owner":"cs-eliseev","description":"The helpers allows you to easy use DATE. Change format, add/sub day, diff date, get quarter - all this is available in this library.","archived":false,"fork":false,"pushed_at":"2019-05-06T04:52:23.000Z","size":88,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T00:44:49.208Z","etag":null,"topics":["collection","collections","converter","cse","date","framework","helper","helpers","library","php","tool","tools","utilities","utility","utils"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cs-eliseev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-03T06:26:53.000Z","updated_at":"2022-10-01T18:06:09.000Z","dependencies_parsed_at":"2022-08-21T09:20:41.283Z","dependency_job_id":null,"html_url":"https://github.com/cs-eliseev/helpers-date","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-date","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-date/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-date/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-date/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cs-eliseev","download_url":"https://codeload.github.com/cs-eliseev/helpers-date/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248872185,"owners_count":21175362,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collection","collections","converter","cse","date","framework","helper","helpers","library","php","tool","tools","utilities","utility","utils"],"created_at":"2024-12-11T03:13:25.020Z","updated_at":"2025-04-14T11:33:46.307Z","avatar_url":"https://github.com/cs-eliseev.png","language":"PHP","funding_links":["https://www.paypal.me/cseliseev/10usd"],"categories":[],"sub_categories":[],"readme":"English | [Русский](https://github.com/cs-eliseev/helpers-date/blob/master/README.ru_RU.md)\n\nDATE CSE HELPERS\n=======\n\n[![Travis (.org)](https://img.shields.io/travis/cs-eliseev/helpers-date.svg?style=flat-square)](https://travis-ci.org/cs-eliseev/helpers-date)\n[![Codecov](https://img.shields.io/codecov/c/github/cs-eliseev/helpers-date.svg?style=flat-square)](https://codecov.io/gh/cs-eliseev/helpers-date)\n[![Scrutinizer code quality](https://img.shields.io/scrutinizer/g/cs-eliseev/helpers-date.svg?style=flat-square)](https://scrutinizer-ci.com/g/cs-eliseev/helpers-date/?branch=master)\n\n[![Packagist](https://img.shields.io/packagist/v/cse/helpers-date.svg?style=flat-square)](https://packagist.org/packages/cse/helpers-date)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://packagist.org/packages/cse/helpers-date)\n[![Packagist](https://img.shields.io/packagist/l/cse/helpers-date.svg?style=flat-square)](https://github.com/cs-eliseev/helpers-date/blob/master/LICENSE.md)\n[![GitHub repo size](https://img.shields.io/github/repo-size/cs-eliseev/helpers-date.svg?style=flat-square)](https://github.com/cs-eliseev/helpers-date/archive/master.zip)\n\nThe helpers allows you to easy use DATE. Change format, add/sub day, diff date, get quarter - all this is available in this library.\n\nProject repository: https://github.com/cs-eliseev/helpers-date\n\n**DATE**\n```php\nif (Date::isToday($date)) {\n    $date = Date::changeDay($date, -7);\n}\n$mount = Date::diff($date, 'now', '%m');\nDate::getQuarterByNumberMonth($mount);\n```\n\n***\n\n## Introduction\n\n[CSE HELPERS](https://github.com/cs-eliseev/helpers/blob/master/README.md) is a collection of several libraries with simple functions written in PHP for people.\n\nDespite using PHP as the main programming language for the Internet, its functions are not enough. \nDATE CSE HELPERS used method: change format, add/sub day, diff date, get quarter and other.\n\n[CSE HELPERS](https://github.com/cs-eliseev/helpers/blob/master/README.md) was created for the rapid development of web applications.\n\n**CSE Helpers project:**\n* [Array CSE helpers](https://github.com/cs-eliseev/helpers-arrays)\n* [Cookie CSE helpers](https://github.com/cs-eliseev/helpers-cookie)\n* [Date CSE helpers](https://github.com/cs-eliseev/helpers-date)\n* [Email CSE helpers](https://github.com/cs-eliseev/helpers-email)\n* [IP CSE helpers](https://github.com/cs-eliseev/helpers-ip)\n* [Json CSE helpers](https://github.com/cs-eliseev/helpers-json)\n* [Math Converter CSE helpers](https://github.com/cs-eliseev/helpers-math-converter)\n* [Phone CSE helpers](https://github.com/cs-eliseev/helpers-phone)\n* [Request CSE helpers](https://github.com/cs-eliseev/helpers-request)\n* [Session CSE helpers](https://github.com/cs-eliseev/helpers-session)\n* [Word CSE helpers](https://github.com/cs-eliseev/helpers-word)\n\nBelow you will find some information on how to init library and perform common commands.\n\n## Install\n\nYou can find the most recent version of this project [here](https://github.com/cs-eliseev/helpers-date).\n\n### Composer\n\nExecute the following command to get the latest version of the package:\n```bash\ncomposer require cse/helpers-date\n```\n\nOr file composer.json should include the following contents:\n```json\n{\n    \"require\": {\n        \"cse/helpers-date\": \"*\"\n    }\n}\n```\n\n### Git\n\nClone this repository locally:\n```bash\ngit clone https://github.com/cs-eliseev/helpers-date.git\n```\n\n### Download\n\n[Download the latest release here](https://github.com/cs-eliseev/helpers-date/archive/master.zip).\n\n## Usage\n\nThe class consists of static methods that are conveniently used in any project. \nSee example [examples-date.php](https://github.com/cs-eliseev/helpers-date/blob/master/examples/examples-date.php).\n\n**GET time by date**\n\nExample:\n```php\nDate::getTime('01.01.2018');\n// 1514754000\n```\n\nUse current date:\n```php\nDate::getTime();\nDate::getTime('now');\n// timestemp\n```\n\nUse relative time:\n```php\nDate::getTime('+1 week 2 days 4 hours 2 seconds');\n// timestemp\n```\n\n**Convert date to format**\n\nExample:\n```php\nDate::toFormat('2018-01-01');\n// 01.01.2018\n```\n\nUse timestamp:\n```php\nDate::toFormat(1514754000);\n// 01.01.2018\n```\n\nChange default format:\n```php\nDate::toFormat(1514754000, 'Y/m/d');\n// 2018/01/01\n```\n\nUse current date:\n```php\nDate::toFormat();\nDate::toFormat('now');\n// d.m.Y\n```\n\nUse relative time:\n```php\nDate::toFormat('+1 week 2 days 4 hours 2 seconds');\n```\n\n**Convert date to SQL**\n\nExample:\n```php\nDate::toSQL('01.01.2018');\n// 2018-01-01\n```\n\nUse timestamp:\n```php\nDate::toSQL(1514754000);\n// 2018-01-01\n```\n\nUse current date:\n```php\nDate::toSQL();\nDate::toSQL('now');\n// Y-m-d\n```\n\nUse relative time:\n```php\nDate::toSQL('+1 week 2 days 4 hours 2 seconds');\n// Y-m-d\n```\n\n**Diff date**\n\nExample:\n```php\nDate::diff('2018-07-01', '2018-07-01');\n// 0\n```\n\nDate format hour:\n```php\nDate::diff('2018-07-01 02:00:00', '01.01.2018 00:00:00', '%h');\n// 2\n```\n\nUse timestamp:\n```php\nDate::diff(strtotime('2018-09-02'), strtotime('2018-07-02'), '%m'));\n// 2\n```\n\nOther format:\n```php\nDate::diff('31.01.2018', 1514754000, '%d/%m'));\n// 30/0\n```\n\nCurrent date:\n```php\nDate::diff('31.01.2018');\nDate::diff('31.01.2018', 'now');\n// %d\n```\n\nUse relative time:\n```php\nDate::diff'31.01.2018', '+1 week');\n// %d\n```\n\n**Current date**\n\nExample:\n```php\nDate::current();\n// d.m.Y\n```\n\nSet format:\n```php\nDate::current(Date::FORMAT_SQL);\n// Y-m-d\n```\n\n**Extreme month date**\n\nGet last day month:\n```php\nDate::extremeMonthDate('11.01.2018');\n// 2018-01-31\n```\n\nGet first day month:\n```php\nDate::extremeMonthDate('28.02.2018', 'Y-m-01');\n// 2018-02-01\n```\n\nUse timestemp:\n```php\nDate::extremeMonthDate(strtotime('28.02.2018'), 'Y-m-01');\n// 2018-02-01\n```\n\nUse current date:\n```php\nDate::extremeMonthDate();\nDate::extremeMonthDate('now');\n// Y-m-last_mounth_day\n```\n\nUse relative date:\n```php\nDate::extremeMonthDate('+1 week');\n// Y-m-last_mounth_day + 1 week\n```\n\n**Get quarter**\n\nExample:\n```php\nDate::getQuarter('31.12.2018 23:59:59');\n// 4\n```\n\nUse timestemp:\n```php\nDate::getQuarter(1514754000);\n// 1\n```\n\nUse current date:\n```php\nDate::getQuarter();\nDate::getQuarter('now');\n// quarter\n```\n\nUse relative time:\n```php\nDate::getQuarter('+1 week 2 days 4 hours 2 seconds');\n// quarter\n```\n\n**Get quarter by number month**\n\nExample:\n```php\nDate::getQuarterByNumberMonth(12);\n// 4\n```\n\n**Change day**\n\nAdd day:\n```php\nDate::changeDay('01.01.2018', 1);\n// 02.01.2018\n```\n\nSub day:\n```php\nDate::changeDay('2018-01-01', -1);\n// 31.12.2017\n```\n\nChange format:\n```php\nDate::changeDay('01.01.2018', -1, Date::FORMAT_SQL);\n// 2017-12-31\n```\n\nUse timestamp:\n```php\nDate::changeDay(timestamp('01.01.2018'), -1, Date::FORMAT_SQL);\n// 2017-12-31\n```\n\n**Check today**\n\nExample:\n```php\nDate::isToday('01.01.2018 00:00:00');\n// false\n```\n\nUse timestamp:\n```php\nDate::isToday(1519804800);\n// false\n```\n\nUse relative time:\n```php\nDate::isToday('now');\n// true\n```\n\n**Check date**\n\nExample:\n```php\nDate::checkDateByTimestamp((new \\DateTime('now'))-\u003eformat('U'));\n// true\n```\n\n**SET TIMEZONE**\n\nExample:\n```php\nDate::setTimezone();\n// UTC\n```\n\nSet timezone:\n```php\nDate::setTimezone('GMT');\n// GMT\n```\n\n**GET TIMEZONE**\n\nExample:\n```php\nDate::getTimezone();\n// UTC\n```\n\n**IS TIMEZONE**\n\nExample:\n```php\nDate::isTimezone();\n// true\n```\n\nSet timezone:\n```php\nDate::isTimezone('GMT');\n// false\n```\n\n## Testing \u0026 Code Coverage\n\nPHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.\n\nGeneral PHPUnit documentation can be found at https://phpunit.de/documentation.html.\n\nTo run the PHPUnit unit tests, execute:\n```bash\nphpunit PATH/TO/PROJECT/tests/\n```\n\nIf you want code coverage reports, use the following:\n```bash\nphpunit --coverage-html ./report PATH/TO/PROJECT/tests/\n```\n\nUsed PHPUnit default config:\n```bash\nphpunit --configuration PATH/TO/PROJECT/phpunit.xml\n```\n\n\n## Donating\n\nYou can support this project [here](https://www.paypal.me/cseliseev/10usd). \nYou can also help out by contributing to the project, or reporting bugs. \nEven voicing your suggestions for features is great. Anything to help is much appreciated.\n\n\n## License\n\nThe DATE CSE HELPERS is open-source PHP library licensed under the MIT license. Please see [License File](https://github.com/cs-eliseev/helpers-date/blob/master/LICENSE.md) for more information.\n\n***\n\n\u003e GitHub [@cs-eliseev](https://github.com/cs-eliseev)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fhelpers-date","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcs-eliseev%2Fhelpers-date","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fhelpers-date/lists"}