I don't know of a built-in function, but you're welcome to use my
daydiff script below.  It actually gives you year, month, day, hour,
minute, second.. Not just days.  But modify it as you desire.

-TG

<?php
# Standard format dates and times
$startdate = "04/12/04";
$starttime = "13:05:01";

$enddate = "10/14/04";
$endtime = "13:05:01";

# Break apart dates and times for mktime
list($smonth,$sday,$syear) = explode("/",$startdate);
list($emonth,$eday,$eyear) = explode("/",$enddate);
list($shour,$sminute,$ssecond) = explode(":",$starttime);
list($ehour,$eminute,$esecond) = explode(":",$endtime);

# Number of seconds in each timeframe, 1 month = 30 days
$secondsequiv =
array("Years"=>31536000,"Months"=>2592000,"Days"=>86400,"Hours"=>3600,"M
inutes"=>60);

# How many seconds between two dates/times
$daydiff = mktime($ehour,$eminute,$esecond,$emonth,$eday,$eyear) -
mktime($shour,$sminute,$ssecond,$smonth,$sday,$syear);

if ($daydiff < 0) { $daydiff *= -1; $negative = TRUE; }

# Just to make sure I didn't use $remainder somewhere else in my script
and forgot
if (isset($remainder)) unset($remainder);

# Cycle through timeframes checking to see if number is large enough to
be a full year/month/day/etc
# If so, find out how many and store remainder for further processing
# If not, set to zero and continue processing
foreach ($secondsequiv as $timeframe=>$seconds) {
  if (isset($remainder)) { $checkvalue = $remainder; } else {
$checkvalue = $daydiff; }
  if ($checkvalue >= $seconds) {
    $daydiffarr[$timeframe] = floor($checkvalue/$seconds);
    $remainder = $daydiff % $seconds;
  } else {
    $daydiffarr[$timeframe] = 0;
  }
}

# If $reminder is never used, then we're dealing with less than a
minute's worth of time diff
if (isset($remainder)) {
  $daydiffarr["Seconds"] = $remainder;
} else {
  $daydiffarr["Seconds"] = $daydiff;
}

# Display results
if ($negative) echo "NEGATIVE!!<br>\n";
foreach ($daydiffarr as $timeframe=>$count) {
  echo "$timeframe = $count<br>\n";
}
?>

> -----Original Message-----
> From: Peter Lauri [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, December 02, 2004 11:38 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Days remaining?
> 
> 
> Best groupmember,
> 
> I have the date 2004-12-24 in a string, and 2004-11-05 in a 
> other. Is there
> any date function that can assist in calculating the number 
> of days left
> until 2004-12-24 when it is 2004-11-05. (the dates are just testdates)
> 
> --
> - Best Of Times
> /Peter Lauri
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to