RE: difference between two times
oops, good point. thanks. On Mon, 4 Mar 2002, Roger Baklund wrote: * Nathan Cowles $query2 = SELECT SEC_TO_TIME(TIME_TO_SEC('$lastout') - TIME_TO_SEC('$firstin')); $result2 = mysql_db_query($database, $query, $connection) or die (Error in query: $query. . mysql_error()); You are assigning the query to $query2, but you execute $query... ;) -- Roger Nathan Cowles StormNet Communications 530.897.4069 - 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
Re: difference between two times
lastout and firstin contain times such as 13:28:01 and 13:27:54. If I use the query you gave me from within phpMyAdmin, the result I get is 7 seconds, exactly what it should be...but I do not know how to use PHP to get the correct result, it is giving me 23. I am accustomed to using mysql_result to get results but it needs to know the result variable ($result), the row (should be 0?), and then the last one is usually the field name, but in this case I don't think I have one because I'm asking it to select a math operation, so where does the result go, and how do I get it with PHP? Thanks. Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: At 13:35 -0800 3/4/02, Nathan Cowles wrote: Paul, You're awesome...thank you. One more question pertaining to this... I'm accustomed to selecting a variable and using something like this: $firstin = mysql_result($result,$row,firstin); to set my variable. What do I want to do here to get the right result into my variable? $query2 = SELECT SEC_TO_TIME(TIME_TO_SEC('$lastout') - TIME_TO_SEC('$firstin')); $result2 = mysql_db_query($database, $query, $connection) or die (Error in query: $query. . mysql_error()); This isn't working, I get 23: $total = mysql_result($result2,0); I guess it depends on what the values of $firstin and $lastout are, and how you're displaying the value of $total. It's hard to say anything without seeing more of the code. Thanks again! Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: Hello, I am trying to get an accurate (nearest 15 minutes would be fine) difference between two times that I have in my database. They are both of type time, and are in the format 00:00:00. For example, if I want the difference between 09:20:00 and 10:43:00, I would like it to give me 01:23:00 as the answer, but all I have been able to get it to do is give me one. It is rounding to the nearest hour. I found this query which seems like it would work, but gives me a NULL result set: SELECT DATE_SUB('11:48:02', INTERVAL '10:37:37' HOUR_SECOND); For two times t1 and t2, compute the difference in seconds like this: SELECT TIME_TO_SEC(t2) - TIME_TO_SEC(t1) If you want the result as a time value, pass it to SEC_TO_TIME(): SELECT SEC_TO_TIME(TIME_TO_SEC(t2) - TIME_TO_SEC(t1)) I am trying to do all of this from PHP, so if you happen to know of a way to make it do the subtraction in PHP without losing all accuracy, please let me know. Thanks for any help you can offer. Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 - 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
Re: difference between two times
At 13:54 -0800 3/4/02, Nathan Cowles wrote: lastout and firstin contain times such as 13:28:01 and 13:27:54. If I use the query you gave me from within phpMyAdmin, the result I get is 7 seconds, exactly what it should be...but I do not know how to use PHP to get the correct result, it is giving me 23. I am accustomed to using mysql_result to get results but it needs to know the result variable ($result), the row (should be 0?), and then the last one is usually the field name, but in this case I don't think I have one because I'm asking it to select a math operation, so where does the result go, and how do I get it with PHP? Thanks. If you want to give the result a name, just supply a column alias and use the alias in your mysql_result() call. But in this case, I don't know if that's the problem. Generally, when someone says that they can't tell what's wrong because not enough of the code is shown, that means you should show some more of the actual code. Not give some sort of verbal description of the problem. Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: At 13:35 -0800 3/4/02, Nathan Cowles wrote: Paul, You're awesome...thank you. One more question pertaining to this... I'm accustomed to selecting a variable and using something like this: $firstin = mysql_result($result,$row,firstin); to set my variable. What do I want to do here to get the right result into my variable? $query2 = SELECT SEC_TO_TIME(TIME_TO_SEC('$lastout') - TIME_TO_SEC('$firstin')); $result2 = mysql_db_query($database, $query, $connection) or die (Error in query: $query. . mysql_error()); This isn't working, I get 23: $total = mysql_result($result2,0); I guess it depends on what the values of $firstin and $lastout are, and how you're displaying the value of $total. It's hard to say anything without seeing more of the code. Thanks again! Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: Hello, I am trying to get an accurate (nearest 15 minutes would be fine) difference between two times that I have in my database. They are both of type time, and are in the format 00:00:00. For example, if I want the difference between 09:20:00 and 10:43:00, I would like it to give me 01:23:00 as the answer, but all I have been able to get it to do is give me one. It is rounding to the nearest hour. I found this query which seems like it would work, but gives me a NULL result set: SELECT DATE_SUB('11:48:02', INTERVAL '10:37:37' HOUR_SECOND); For two times t1 and t2, compute the difference in seconds like this: SELECT TIME_TO_SEC(t2) - TIME_TO_SEC(t1) If you want the result as a time value, pass it to SEC_TO_TIME(): SELECT SEC_TO_TIME(TIME_TO_SEC(t2) - TIME_TO_SEC(t1)) I am trying to do all of this from PHP, so if you happen to know of a way to make it do the subtraction in PHP without losing all accuracy, please let me know. Thanks for any help you can offer. Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 - 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
Re: difference between two times
The file is available at http://estore.homeip.net/time/pctimesheetnew.php.txt; How would I supply a column alias? Thanks. Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: At 13:54 -0800 3/4/02, Nathan Cowles wrote: lastout and firstin contain times such as 13:28:01 and 13:27:54. If I use the query you gave me from within phpMyAdmin, the result I get is 7 seconds, exactly what it should be...but I do not know how to use PHP to get the correct result, it is giving me 23. I am accustomed to using mysql_result to get results but it needs to know the result variable ($result), the row (should be 0?), and then the last one is usually the field name, but in this case I don't think I have one because I'm asking it to select a math operation, so where does the result go, and how do I get it with PHP? Thanks. If you want to give the result a name, just supply a column alias and use the alias in your mysql_result() call. But in this case, I don't know if that's the problem. Generally, when someone says that they can't tell what's wrong because not enough of the code is shown, that means you should show some more of the actual code. Not give some sort of verbal description of the problem. Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: At 13:35 -0800 3/4/02, Nathan Cowles wrote: Paul, You're awesome...thank you. One more question pertaining to this... I'm accustomed to selecting a variable and using something like this: $firstin = mysql_result($result,$row,firstin); to set my variable. What do I want to do here to get the right result into my variable? $query2 = SELECT SEC_TO_TIME(TIME_TO_SEC('$lastout') - TIME_TO_SEC('$firstin')); $result2 = mysql_db_query($database, $query, $connection) or die (Error in query: $query. . mysql_error()); This isn't working, I get 23: $total = mysql_result($result2,0); I guess it depends on what the values of $firstin and $lastout are, and how you're displaying the value of $total. It's hard to say anything without seeing more of the code. Thanks again! Nathan Cowles On Mon, 4 Mar 2002, Paul DuBois wrote: Hello, I am trying to get an accurate (nearest 15 minutes would be fine) difference between two times that I have in my database. They are both of type time, and are in the format 00:00:00. For example, if I want the difference between 09:20:00 and 10:43:00, I would like it to give me 01:23:00 as the answer, but all I have been able to get it to do is give me one. It is rounding to the nearest hour. I found this query which seems like it would work, but gives me a NULL result set: SELECT DATE_SUB('11:48:02', INTERVAL '10:37:37' HOUR_SECOND); For two times t1 and t2, compute the difference in seconds like this: SELECT TIME_TO_SEC(t2) - TIME_TO_SEC(t1) If you want the result as a time value, pass it to SEC_TO_TIME(): SELECT SEC_TO_TIME(TIME_TO_SEC(t2) - TIME_TO_SEC(t1)) I am trying to do all of this from PHP, so if you happen to know of a way to make it do the subtraction in PHP without losing all accuracy, please let me know. Thanks for any help you can offer. Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 Nathan Cowles StormNet Communications 530.897.4069 - 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 Nathan Cowles StormNet Communications 530.897.4069 - 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
Re: difference between two times
The file is attached and is also available at http://estore.homeip.net/time/pctimesheetnew.php.txt; What do you mean by supplying a column alias...how would I do that? Thanks. Instead of writing: SELECT some-long-expression Write: SELECT some-long-expression AS xyz Then the output column will be named xyz, and you can do this: $total = mysql_result($result2, 0, xyz); But now that I look more closely at your code again, the problem is actually fairly simple. Your query is in $query2, but you're passing $query to mysql_db_query(). That's bound to give you a result you don't want. :-) - 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
RE: difference between two times
* Nathan Cowles $query2 = SELECT SEC_TO_TIME(TIME_TO_SEC('$lastout') - TIME_TO_SEC('$firstin')); $result2 = mysql_db_query($database, $query, $connection) or die (Error in query: $query. . mysql_error()); You are assigning the query to $query2, but you execute $query... ;) -- Roger - 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