Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP 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 July 20th, 2006, 03:47 AM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to calculate a number of days between 2 date

Dear all,

I have the following script:

var Day1 = dateObj1.value.substring( 0, 2 );
var Month1 = dateObj1.value.substring( 3, 5 );
var Year1 = dateObj1.value.substring( 6, 10 );
var Dt1 = Year1 + Month1 + Day1;


var Day2 = dateObj2.value.substring( 0, 2 );
var Month2 = dateObj2.value.substring( 3, 5 );
var Year2 = dateObj2.value.substring( 6, 10 );
var Dt2 = Year2 + Month2 + Day2;

if( Dt1 > Dt2 || Dt1 == "" || Dt2 == "")
{

return true;

}

For example, if Dt1 value is 20050601 and Dt2 value is 20050523, how can i get the number of days?. besides that, i also want to check the condition if Dt1 value <=Dt2 + 60 prompt messgae"ok" otherwise prompt message "<= 60days of PPC date"

Any helps is highly appreciated.

Thanks in advance...


 
Old July 20th, 2006, 07:09 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your script can be highly simplified to just:

if (dateObj1.after(dateObj2)) return true;

To calculate the number of days between the two objects, you can do date math on the Date.getTime() return value:

int days = (dateObj1.getTime() - dateObj2.getTime()) / (1000 * 60 * 60 * 24);

If dateObj1 is not necessarily after dateObj2, you may want to use Math.abs(int) to always get a positive number.

Jon Emerson
http://blogs.adobe.com/jon.emerson/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate # of work days ? kscase SQL Server 2005 3 June 9th, 2007 09:11 PM
Todays date and date of 3 days later Singh591 Visual Basic 2005 Basics 1 December 21st, 2006 06:06 PM
Calculating number of days between multiple dates Vann Access 4 December 3rd, 2004 08:26 PM
Calculate Business Days - MS access 97 snoopy92211 Access VBA 0 October 13th, 2004 02:13 PM
How to calculate the work days beetwen two dates. andres_pm Javascript 1 October 7th, 2004 06:23 AM





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