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;
}
?>
Description
This function is an alias of: DateTime::add
date_add
lanlife4real
10-Jan-2010 05:19
10-Jan-2010 05:19
Hyun Woo Shin
27-Mar-2009 02:32
27-Mar-2009 02: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 04:37
09-Sep-2008 04: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";
}
?>
