Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2008, 12:14 PM
Authorized User
 
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hour Diff in javascript doen's work well

Hi I have got the following code to calculate hours difference between two dates. The problem is for months that have 31 days.

var consult = new Date();
consult.setDate(2); //2nd
consult.setMonth(3); //april
consult.setYear(2008);
consult.setHours(0);
consult.setMinutes(0);
consult.setSeconds(0);

var upsi = new Date();
upsi.setDate(31); //31st
upsi.setMonth(2); //march
upsi.setYear(2008);
upsi.setHours(0);
upsi.setMinutes(0);
upsi.setSeconds(0);

var hoursDiff = consult.getTime()-upsi.getTime();
hoursDiff = ((hoursDiff / 1000) / 60) / 60;
hoursDiff = Math.round(hoursDiff);

hoursDiff doesn't return the appropiate value.

Any suggestions?

Thanks
Gabriel

 
Old April 3rd, 2008, 12:47 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi Gabriel!!

The best way to do it ,to get the Day difference between two dates and apply hours logic.
Hope this will help you.

Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hour by Hour Matrix Report Ed_Conde BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 August 12th, 2008 02:51 PM
Javascript isnt work well on my aspx page msbsam ASP.NET 2.0 Professional 1 July 11th, 2008 08:00 AM
diff b/w javascript validation & server side valid ashu VS.NET 2002/2003 1 March 27th, 2007 09:30 AM
javaScript function in asp.net not work in firefox rsanuj ASP.NET 1.x and 2.0 Application Design 1 February 8th, 2007 11:37 AM
Javascript fdoesnt work.. vanjamier Pro JSP 1 February 8th, 2005 05:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.