Coder Social home page Coder Social logo

sam1975sam / datetimehelper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marshung24/datetimehelper

2.0 0.0 0.0 29 KB

DatetimeHelper library, providing format judgment, time increase and decrease, etc.

License: MIT License

PHP 100.00%

datetimehelper's Introduction

DatetimeHelper

Time processing library, providing format judgment, time increase and decrease, etc.

Continuation library marshung/helper, only keep and maintain DatetimeHelper

Latest Stable Version Total Downloads Latest Unstable Version License

Outline

Composer Install

# composer require marsapp/datetimehelper

Include

Include composer autoloader before use.

require __PATH__ . "vendor/autoload.php";

Namespace use:

use marsapp\helper\datetime\DatetimeHelper;

isDate()

Determine if the date is legal

isDate($date) : Bool

Example :

if (DatetimeHelper::isDate('2019-01-15)) {
	die('Date format error');
}

dateAdd()

Date calculation - increase

dateAdd(String $date, Int $add = '1', String $unit = 'day', String $format = 'Y-m-d') : string

$unit: day, month, year, hour, minute, second

Example :

DatetimeHelper::dateAdd('2019-01-31', '1', 'day');
// result: 2019-02-01

DatetimeHelper::dateAdd('2019-01-31', '1', 'month');
// result: 2019-02-28

DatetimeHelper::dateAdd('2019-01-31 12:34:56', '13', 'month', 'Y-m-d H:i:s');
// result: 2020-02-29 12:34:56

DatetimeHelper::dateAdd('2019-01-31 12:34:56', '20', 'hour', 'Y-m-d H:00:00');
// result: 2019-02-01 09:00:00

dateReduce()

Date calculation - reduction

dateReduce(String $date, Int $reduce = '1', String $unit = 'day', String $format = 'Y-m-d') : string

$unit: day, month, year, hour, minute, second

Example :

DatetimeHelper::dateReduce('2019-01-01', '1', 'day');
// result: 2018-12-31

DatetimeHelper::dateReduce('2019-01-31', '2', 'month');
// result: 2018-11-30

DatetimeHelper::dateReduce('2020-02-29 12:34:56', '1', 'year', 'Y-m-d H:i:s');
// result: 2019-02-28 12:34:56

dateCal()

Date calculation

dateCal(String $date, Int $difference = '1', String $unit = 'day', String $format = 'Y-m-d') : string

$difference positive is add, negative is reduce
$unit: day, month, year, hour, minute, second

Example :

DatetimeHelper::dateCal('2019-01-31', '1', 'month');
// result: 2019-02-28

DatetimeHelper::dateCal('2020-02-29', '-1', 'year');
// result: 2019-02-28

dateIterator()

Get Date Iterator - Iteration Date in Days

dateIterator($startDate, $endDate)

Example :

$daterange = DateTimeHelper::dateIterator('2018-01-01', '2018-01-31');
foreach($daterange as $date){
    echo $date->format('Y-m-d') . '<br>';
}

datetimehelper's People

Contributors

marshung24 avatar

Stargazers

Vitor Silva avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.