Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 2nd, 2008, 01:14 PM
Authorized User
 
Join Date: Nov 2005
Location: lima, lima, Peru.
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

Reply With Quote
  #2 (permalink)  
Old April 3rd, 2008, 01:47 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
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

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

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 03:51 PM
Javascript isnt work well on my aspx page msbsam ASP.NET 2.0 Professional 1 July 11th, 2008 09:00 AM
diff b/w javascript validation & server side valid ashu VS.NET 2002/2003 1 March 27th, 2007 10: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



All times are GMT -4. The time now is 04:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.