Contact Us

6ta. Avenida 2-48 zona 13, Guatemala, Guatemala.

T +(502) 2458-4464 • Email: info@pixtig.com

Write us :)

Quote
Your budget in US Dollars ($)
Current Website (if you have one)
I want to be part of your team
Inquiry
Can you help us?

Blog

We are passionate about Drupal and obsessed with adding significant content to the web. We design, we program, we develop, we comunicate, we teach and blogging.

kimberly's picture

Aumentar un mes a una fecha

By: 
kimberly
Tags: 
PHP
Paypal
Fuctions
Parameters

Esta vez necesitaba generar una fecha futura para especificar en paypal el inicio de cobros recurrentes, para la creación de cobros recurrentes he utilizando el método CreateRecurringPaymentsProfile con el parámetro PROFILESTARTDATE, con la siguiente función he podido obtener cual es el siguiente mes con día 2 y hora.

Código: 
/**
 * Agregarle un mes a la fecha actual
 * @param int $monthToAdd
 * @param string $start_day
 * @param string $start_hour
 * @return string
 */
function month_add($monthToAdd = 1, $start_day = "01", $start_hour = "01"){
 
    $d1 = DateTime::createFromFormat('Y-m-d H:i:s', date("Y-m-") . $start_day . ' '.$start_hour.':00:00');
    $year = $d1->format('Y');
    $month = $d1->format('n');
    $day = $d1->format('d');
 
    $year += floor($monthToAdd/12);
    $monthToAdd = $monthToAdd%12;
    $month += $monthToAdd;
    if($month > 12) {
        $year ++;
        $month = $month % 12;
        if($month === 0)
            $month = 12;
    }
    if(!checkdate($month, $day, $year)) {
        $d2 = DateTime::createFromFormat('Y-n-j', $year.'-'.$month.'-1');
        $d2->modify('last day of');
    }else {
        $d2 = DateTime::createFromFormat('Y-n-d', $year.'-'.$month.'-'.$day);
    }
    $d2->setTime($d1->format('H'), $d1->format('i'), $d1->format('s'));
    return $d2->format('Y-m-d')."T".$d2->format('H:i:s');
}