Closed cycles in PHP

Asked

Viewed 24 times

0

We create the following function:

public function get_ciclo_atual($hoje, $dia_inicial=21, $dia_final=20){
    $ciclo = array();
    if(date("d", strtotime($hoje)) >= $dia_inicial){
        $ciclo[0] = date("Y", strtotime($hoje))."-".date("m", strtotime($hoje))."-".$dia_inicial;
        $ciclo[1] = date("Y", strtotime($hoje))."-".date("m", strtotime($hoje." +1 month"))."-".$dia_inicial;
    }else{
        $ciclo[0] = date("Y", strtotime($hoje))."-".date("m", strtotime($hoje." -1 month"))."-".$dia_inicial;
        $ciclo[1] = date("Y", strtotime($hoje))."-".date("m", strtotime($ciclo[0]." +1 month"))."-".$dia_final;     
    }

    return $ciclo;
}

To return a specific period, based on my current date. My return then is this way:

$ciclo_atual = date('Y-m-d', strtotime('-1 months'));
$ciclo_atual = $this->get_ciclo_atual($ciclo_atual);

In this case, today 21/06/2021 we have the cycle: 2021-05-21 a 2021-06-20, representing the last closing cycle and is working.

I would like to create, based on this, a foreach() where I could get every cycle of the year, which would be from Jan to Ten, and remembering that of Ten 2021-12-21 a 2022-01-20.

How could I perform this?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.