Databases :: MySql :: Substracting TIME values |
|||
| By: Squibi |
Date: 06/10/2003 00:00:00 |
Points: 20 | Status: Answered Quality : Excellent |
|
Hi, I want to substract two TIME column values, and insert the resultant value in a third TIME column. What is the best way to do this? I tried using the basic - operator but the resultant value is not a TIME value, so I can not insert it in the third column. Thanks |
|||
| By: VGR | Date: 07/10/2003 18:37:00 | Type : Comment |
|
| true. The result should be an integer of some sort (after all, it is NOT a time, you understand this ? ;-) but you could format it to a TIME value using the various "date and time functions" |
|||
| By: VGR | Date: 07/10/2003 18:39:00 | Type : Comment |
|
| Also : TIMEDIFF(ARGUMENTS) (added in 4.1.1.) |
|||
| By: VGR | Date: 07/10/2003 18:40:00 | Type : Comment |
|
| in fact, I suggest you simply do SEC_TO_TIME(timediff) |
|||
| By: VGR | Date: 07/10/2003 18:42:00 | Type : Answer |
|
| found. mysql> select TIME_TO_SEC('10:00:34')-time_to_sec('09:00:30'); +-------------------------------------------------+ | TIME_TO_SEC('10:00:34')-time_to_sec('09:00:30') | +-------------------------------------------------+ | 3604 | +-------------------------------------------------+ 1 row in set (0.03 sec) mysql> select SEC_TO_TIME(TIME_TO_SEC('10:00:34')-time_to_sec('09:00:30')); +--------------------------------------------------------------+ | SEC_TO_TIME(TIME_TO_SEC('10:00:34')-time_to_sec('09:00:30')) | +--------------------------------------------------------------+ | 01:00:04 | +--------------------------------------------------------------+ 1 row in set (0.05 sec) |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








