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

Resolving Package Conflict with Level-Zero Installation; Fixing dpkg Error

Preparing to unpack level-zero_1.20.2+u24.04_amd64.deb ... Unpacking level-zero ( 1.20.2 ) ... dpkg: error processing archive level-zero_1....