mevr
mevr

Reputation: 1125

Calculate date before n days of a month

How to calculate a date before 10 days of every month end ?Am using codeigniter platform.

I need to check whether a date is within 10 days before the end of every month.

Please help

Upvotes: 0

Views: 475

Answers (3)

elddenmedio
elddenmedio

Reputation: 1030

you can create a library with this

class Calculate_days{
    function __construct() {
        parent::__construct();
    }

    function calculate( $to_day = date("j") ){
        $days_month  = date("t");

        $result      = (int) $days_month - $to_day;

        if( $result <= 10){
            $result  = array("type" => TRUE, "missing" => $result . 'days');

            return $result;
        }
        else{
            $result  = array("type" => FASLE, "missing" => $result . 'days');

            return $result;
        }
    }
}

controller.php

function do_somthing(){
    $this->load->library('Calculate_days');

    $result  = $this->Calculate_days->calculate(date("j"));

    var_dump($result);
}

Upvotes: 1

splash58
splash58

Reputation: 26153

i need to check whether a date is within10 days before the end of a month

function testDate($date) {

$uDate = strtotime($date);
return date("m", $uDate) != date("m", strtotime("+10 days", $uDate));
}

echo testDate("2016-03-07") ? "Yes" :"No"; // No
echo testDate("2016-03-27") ? "Yes" :"No"; // Yes

Upvotes: 1

Naumov
Naumov

Reputation: 1167

You can try using date_modify function for example see this php documentation http://php.net/manual/en/datetime.modify.php

Upvotes: 2

Related Questions