downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_create_from_format> <checkdate
Last updated: Fri, 20 May 2011

view this page in

date_add

(PHP 5 >= 5.3.0)

date_addAlias de DateTime::add()

Descripción

Esta función es un alias de: DateTime::add()



date_create_from_format> <checkdate
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes date_add
lanlife4real 10-Jan-2010 11:19
This function allows the addition of day(s),month(s),year(s) to the original date while still preserving the Hours, minutes and seconds
You can also modify to add to hours, miuntes and even seconds.
 
<?php
function add_date($givendate,$day=0,$mth=0,$yr=0) {
     
$cd = strtotime($givendate);
     
$newdate = date('Y-m-d h:i:s', mktime(date('h',$cd),
   
date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
   
date('d',$cd)+$day, date('Y',$cd)+$yr));
      return
$newdate;
              }

?>
Hyun Woo Shin 27-Mar-2009 07:32
Just add month(s) on the orginal date.

<?php
function add_date($orgDate,$mth){
 
$cd = strtotime($orgDate);
 
$retDAY = date('Y-m-d', mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)));
  return
$retDAY;
}
?>
raph 09-Sep-2008 09:37
A little function to add 2 time lenghts. Enjoy !

<?php
function AddPlayTime ($oldPlayTime, $PlayTimeToAdd) {

   
$pieces = split(':', $oldPlayTime);
   
$hours=$pieces[0];
   
$hours=str_replace("00","12",$hours);
   
$minutes=$pieces[1];
   
$seconds=$pieces[2];
   
$oldPlayTime=$hours.":".$minutes.":".$seconds;

   
$pieces = split(':', $PlayTimeToAdd);
   
$hours=$pieces[0];
   
$hours=str_replace("00","12",$hours);
   
$minutes=$pieces[1];
   
$seconds=$pieces[2];
   
   
$str = $str.$minutes." minute ".$seconds." second" ;
   
$str = "01/01/2000 ".$oldPlayTime." am + ".$hours." hour ".$minutes." minute ".$seconds." second" ;
   
   
// Avant PHP 5.1.0, vous devez comparer avec  -1, au lieu de false
   
if (($timestamp = strtotime($str)) === false) {
        return
false;
    } else {
       
$sum=date('h:i:s', $timestamp);
       
$pieces = split(':', $sum);
       
$hours=$pieces[0];
       
$hours=str_replace("12","00",$hours);
       
$minutes=$pieces[1];
       
$seconds=$pieces[2];
       
$sum=$hours.":".$minutes.":".$seconds;
       
        return
$sum;
       
    }
}

$firstTime="00:03:12";
$secondTime="02:04:34";

$sum=AddPlayTime($firstTime,$secondTime);
if (
$sum!=false) {
    echo
$firstTime." + ".$secondTime." === ".$sum;
}
else {
    echo
"failed";
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites