Re: Subtracting times?
| From: | Hugh Bothwell | Date: | Sun, 24 Jun 2001 19:09:19 +0000 |
| Subject: | Re: Subtracting times? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-9799@lists.php.net to get a copy of this message | ||
""Matthew Cothier"" <matthewcothier@hotmail.com> wrote in message
news:LAW2-F311J5NPAk94eM0001149b@hotmail.com...
> I really need help here. What I am trying to do is the following.
Which database are you using? What format is it returning the date and
time in (string or integer)? It may be simpler to coerce them to integers
and convert that way with div/mod and mktime().
> if($row[3] == $today){
First recommendation: use mysql_fetch_array() (or the equivalent). It
makes life _so_ much simpler, ie $row["date"], $row["start_time"],
$row["end_time"]
> $today = date("m.d.y");
> $time = date("g:i a");
Second recommendation: do time math in decimal seconds.
define("SECONDS_PER_DAY", 86400);
$now = time();
$today = $now - ( $now % SECONDS_PER_DAY );
$tomorrow = $today + SECONDS_PER_DAY;
// this may be easier if date and time are returned as strings
$start_time = strtotime($row["date"] . " " . $row["start_time"]);
$end_time = strtotime($row["date"] . " " . $row["end_time"]);
if ($start_time >= $tomorrow) { // doesn't start today
$when = $row["date"]." at ".$row["start_time"];
}
else if ($start_time > $now) { // starts today but not yet
$when = "Today at ".$row["start_time"];
}
else if ($end_time >= $now) { // already started, ends later
$when = "Now showing";
}
else { // already ended
$when = "Over";
}