we can add days in date time very easily.
lets we have a date $date =”2010-06-04 12:45″ . we want to add some days with it.
lets the day is $days = 90;
so adding day into date fast we need to convert date in millisecond. we can do this easily by a php function strtotime();
so we can write $date = strtotime(“2010-06-04 12:45″);
then we can use this function to add a date.
$addeddate= date(“Y-m-d H:i:s”, $date+((60*60)*24*$days));
it will return 2010-11-11 12:45:50 .
that’s it. we can difference between two days that way also.
there is another way but it take only y-m-d .
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date – $start_date;
}
$currentTime=date(‘Y-m-d’);
$date =”2010-06-04 12:45″;
$end = date(‘Y-m-d’, strtotime($date));
this will convert date in to this
if date = “2010-06-04″;
the call the function
$dif=dateDiff(“-”, $end, $currentTime);
if out date format is 2010/06/04 then
we call it this way $diff =dateDiff(“/”,$end,$currentTime);