Welcome Guest, Not a member yet? Register   Sign In
How to get date an interval of Date using the Time class?
#3

(10-25-2021, 12:42 AM)InsiteFX Wrote: You would need to extend the Time class and add the method you need to it.

Hi, I wrote a small helper, hope to help:

PHP Code:
<?php

use CodeIgniter\I18n\Time;

if (!
function_exists('getDateInterval')) {
    /**
    * Ottiene un intervallo di date
    * 
    * @param int days
    * 
    * @return array
    */
    function getDateInterval(int $days)
    {
        $period = new DatePeriod(
            new DateTime("now"),
            new DateInterval("P1D"),
            new DateTime("now +${days} day")
        );

        $results = [];

        foreach ($period as $p) {
            $results[] = Time::createFromInstance($p);
        }

        return $results;
    }

Reply


Messages In This Thread
RE: How to get date an interval of Date using the Time class? - by sfarzoso - 10-25-2021, 01:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB