IT Community - Software Programming, Web Development and Technical Support

Diff. between dates

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/...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-30-2007, 03:02 AM
jegan jegan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 161
jegan is on a distinguished road
Default Diff. between dates

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');?>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 02:17 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0