[PHP-DB] subtracting times

2003-03-08 Thread David Rice


I know I asked this before buy no-one gave me an answer i was looking for, I 
want to subtract two times and the ammount of hours worked to 2decimal 
places (3.41 hours)

cheers,
dave
_
Use MSN Messenger to send music and pics to your friends 
http://messenger.msn.co.uk

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


Re: [PHP-DB] Subtracting times?

2001-06-24 Thread Hugh Bothwell

Matthew Cothier [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

 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;
}



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Subtracting times?

2001-06-23 Thread Matthew Cothier

I really need help here. What I am trying to do is the following.

-

$today = date(m.d.y);
$time = date(g:i a);

if($row[3] == $today){

if(($row[4]  $time) and ($time  $row[6])){

print(Now Showing);

} else {

print(Today at $row[4]);

}

} else {

print($row[3] at $row[4]);

}



$row[3] -- Date stored in database i.e 06.23.01
$row[4] -- Start time stored in database i.e 7.00 pm
$row[6] -- End time stored in database i.e 7.30 pm




My problem is that when it looks for the difference in time it works fine 
with say :

start time = 7:00 pm
end time = 8:00 pm

But as soon as I go into:

start time = 7:00 pm
end time = 7.35 pm

it mucks up!


Please help!! What do I need to do?
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Subtracting times?

2001-06-23 Thread Ted Rolle

check out http://www.php.net/manual/en/function.mktime.php
If you still need assistance, I'm here.

On Sun, 24 Jun 2001, Matthew Cothier wrote:

 I really need help here. What I am trying to do is the following.

 -

 $today = date(m.d.y);
 $time = date(g:i a);

 if($row[3] == $today){

   if(($row[4]  $time) and ($time  $row[6])){

   print(Now Showing);

   } else {

   print(Today at $row[4]);

   }

 } else {

 print($row[3] at $row[4]);

 }

 

 $row[3] -- Date stored in database i.e 06.23.01
 $row[4] -- Start time stored in database i.e 7.00 pm
 $row[6] -- End time stored in database i.e 7.30 pm




 My problem is that when it looks for the difference in time it works fine
 with say :

 start time = 7:00 pm
 end time = 8:00 pm

 But as soon as I go into:

 start time = 7:00 pm
 end time = 7.35 pm

 it mucks up!


 Please help!! What do I need to do?
 _
 Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]