Guest User

Untitled

a guest
Aug 21st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. Mysql total elapsed times from two dates
  2. id created start stop
  3. 1 28-01-2011 23:00 28-01-2011 23:00 28-01-2011 23:01
  4. 2 28-01-2011 23:10 28-01-2011 23:10 28-01-2011 23:11
  5.  
  6. select sum(unix_timestamp(stop) -
  7. unix_timestamp(start))/60 from table
  8. where date(created) = '28-01-2011';
  9.  
  10. mysql> select now(), date_add(now(), interval 10 minute);
  11. +---------------------+-------------------------------------+
  12. | now() | date_add(now(), interval 10 minute) |
  13. +---------------------+-------------------------------------+
  14. | 2011-10-04 13:29:56 | 2011-10-04 13:39:56 |
  15. +---------------------+-------------------------------------+
  16. 1 row in set (0.01 sec)
  17.  
  18. mysql> select sum(unix_timestamp(now()) -
  19. unix_timestamp(date_add(now(), interval 10 minute)));
  20. +----------------------------------------------------------------------------------+
  21. | sum(unix_timestamp(now()) - unix_timestamp(date_add(now(), interval 10 minute))) |
  22. +----------------------------------------------------------------------------------+
  23. | -600 |
  24. +----------------------------------------------------------------------------------+
  25. 1 row in set (0.00 sec)
  26.  
  27.  
  28. mysql> select sum(unix_timestamp(now()) -
  29. unix_timestamp(date_add(now(), interval 10 minute))) / 60 ;
  30. +---------------------------------------------------------------------------------------+
  31. | sum(unix_timestamp(now()) - unix_timestamp(date_add(now(), interval 10 minute))) / 60 |
  32. +---------------------------------------------------------------------------------------+
  33. | -10.0000 |
  34. +---------------------------------------------------------------------------------------+
  35. 1 row in set (0.00 sec)
Add Comment
Please, Sign In to add comment