Login    Forum    Search    FAQ   Blog

Board index » Client-Side Development » Javascript




 Page 1 of 1 [ 3 posts ] 



Author Message
 Post subject: Date difference using java script
 Post Posted: Tue Aug 04, 2009 7:57 pm 
Offline

Joined: Sat Feb 21, 2009 3:06 pm
Posts: 33
hi all,

I have to find the date differences between date ranges using JAVASCRIPT


date format is MMDDYY Eg: 041109

for eg: Date1=041209 , Date2=051209


the answer has to be in no of days .......

Please Help Me, Quick


Top 
 Post subject: Re: Date difference using java script
 Post Posted: Tue Aug 04, 2009 7:58 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
http://www.codeproject.com/KB/scripting/Javascript.aspx


Top 
 Post subject: Re: Date difference using java script
 Post Posted: Tue Aug 04, 2009 7:58 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
function timeDifference(startDate,endDate)
{
date1 = startDate;
date2 = endDate;
laterdate = date1.split(”-”);
laterY=laterdate[0];
laterM=laterdate[1];
laterD=laterdate[2];
earlierdate = date2.split(”-”);
earlierY=earlierdate[0];
earlierM=earlierdate[1];
earlierD=earlierdate[2];
var laterdate = new Date(laterY,laterM,laterD);
var earlierdate = new Date(earlierY,earlierM,earlierD);
var difference = laterdate.getTime() – earlierdate.getTime();
var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference -= hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference -= minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);
return daysDifference;
}


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 3 posts ] 




Board index » Client-Side Development » Javascript


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron