MySQL: Calculate DATE, TIME difference in SQL statement using MySQL DB

Following examples showing how to calculated DATE, TIME differences in SQL statement in MySQL database.

Functions used in the following examples are TIMEDIFF and DATEDIFF

 select TIMEDIFF('2011-10-31 12:50:56' , '2011-09-23 12:50:21')   
 The above outputs : 838:59:59  
 select TIMEDIFF('15:50:56' , '12:55:21')   
 The above SQL outputs: 02:55:35  
 select DATEDIFF('2011-10-31 12:50:56' , '2011-09-23 12:50:21')   
 The above SQL outputs: 38  
 select DATEDIFF('2011-10-31' , '2011-09-23')   
 The above SQL outputs: 38  

2 comments:

  1. how i can calculate date and time difference in php diff will be count seconds also they plz give idea about that module .....

    ReplyDelete
  2. Hi,

    There is a convenience method in php - 'date_diff'.
    Pls look at http://php.net/manual/en/datetime.diff.php

    The input this method are DateTime objects.
    The output can be formatted in several types including sec.
    Pls take a look at http://www.php.net/manual/en/datetime.format.php

    ReplyDelete

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...