hi.

store the information in a datetime column for easy handling.

check out the function DATE_ADD() or DATE_SUB() on this page:
http://www.mysql.com/doc/D/a/Date_and_time_functions.html
it has examples of usage that could be helpful.

i would do something like this:
select TO_DAYS(secondDate) - TO_DAYS(firstDate),
         HOUR(secondDate)-HOUR(firstDate)
from your_table;

or to get more complicated:

select (TO_DAYS(secondDate) - TO_DAYS(firstDate)) * 24 +
HOUR(secondDate)-HOUR(firstDate) from your_table;

find out the amount of days difference between the 2 dates, multiply by 24
to change it to hours, then add the difference in hours...
that will probably do what you're looking for.

hth.
-ravi.

-----Original Message-----
From: Sommai Fongnamthip [mailto:[EMAIL PROTECTED]]
Sent: October 18, 2001 4:27 AM
To: [EMAIL PROTECTED]
Subject: time calculate


hi,
        I'd like to calculate hour usage between 2 time value.  Which data type I
should to use in mysql? and how to write sql to calculate hour usage
especially when the second time is in the next day??

Thanks
SF


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to