visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: Substracting TIME values


By: Squibi U.S.A.  Date: 06/10/2003 00:00:00  English  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 English  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 English  Type : Comment
Also : TIMEDIFF(ARGUMENTS)

(added in 4.1.1.)
By: VGR Date: 07/10/2003 18:40:00 English  Type : Comment
in fact, I suggest you simply do SEC_TO_TIME(timediff)
By: VGR Date: 07/10/2003 18:42:00 English  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

EContact
browser fav
page generated in 297.149900 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page