This is a discussion on Diff. between dates within the PHP Programming forums, part of the Web Development category; This function will return the difference between two date - MYSQL DATE/DATETIME format. Ability to return the Minutes/Hours/Days/...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| This function will return the difference between two date - MYSQL DATE/DATETIME format. Ability to return the Minutes/Hours/Days/Weeks/Months/Years time difference. <?php //Find the difference in months (MYSQL DATETIME/DATE Format) function find_difference($start_date,$end_date){ list($date,$time) = explode(' ',$start_date); if($time == NULL){$time = '00:00:00';} $startdate = explode("-",$date); $starttime = explode(":",$time); list($date,$time) = explode(' ',$end_date); if($time == NULL){$time = '00:00:00';} $enddate = explode("-",$date); $endtime = explode(":",$time); $secons_dif = mktime($endtime[0],$endtime[1],$endtime[2],$enddate[1],$enddate[2],$enddate[0]) - mktime($starttime[0],$starttime[1],$starttime[2],$startdate[1],$startdate[2],$startdate[0]); //Different can be returned in many formats //In Minutes: floor($secons_dif/60); //In Hours: floor($secons_dif/60/60); //In days: floor($secons_dif/60/60/24); //In weeks: floor($secons_dif/60/60/24/7; //In Months: floor($secons_dif/60/60/24/7/4); //In years: floor($secons_dif/365/60/24); //We will return it in months $difference = floor($secons_dif/60/60/24/7/4); return $difference; } echo find_difference('2005-05-12','2006-05-13 00:00:00');?> |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Show all the dates between two dates in YYYY-MM-DD format | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 03-11-2008 09:05 PM |
| Diff bt Switch,Hub,Bridges | vadivelanvaidyanathan | Server Management | 1 | 07-16-2007 09:15 AM |
| Diff between Gif and Bmp | sivakumar | Web Design Help | 1 | 07-11-2007 01:49 AM |
| Diff 'V' and 'U' Shape | vigneshgets | Software Testing | 0 | 05-17-2007 06:17 AM |
| dates | swoosh | VB.NET Programming | 0 | 03-15-2007 07:08 PM |