Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datedifference in months

Status
Not open for further replies.

Jeet2004

MIS
Jun 29, 2005
96
US
Here's what i need to do.
on my webpage i have three boxes one for each date, month and year.
I need to compare todays date and this date (from textboxes)
and see if the difference is more than 10 months.

I dont know how to calculat the difference in months.
One thing which comes to my mind is to use every month as 30 days in that case i get the dates difference in milliseconds and then divide by some numbers to get exact difference in month but its not the accurate way to do it.
If someone knows any better way please let me know.
Thanks.
 
So if a month ISN'T 30 days, is it just from one month to the SAME DAY of the next month?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
P.S., Are the text boxes able to be set to a future date? ...a past date? ... both? Are you interested in whether the text box dates are 10 months AFTER today or 10 months BEFORE today?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
The text boxes can be set for something for the same year as current date's year ( for example for if we do that today 1\17\2006 then you can set any date for 2006)
what i want to see is if for today some on enters
3\17\2005 there should be no error message and if its 2\17\2005 it should throw error message
so i need in past
there wont be any comparison to future dates
Hope i am able to explain my situatio if not please let me know
thanks for taking time to help me
 
This answer assumes you can use the JS you know to get here. Let us know if this is clear:

Code:
if(thisYear == textBoxYear)
{
 var monthDiff = thisMonth - textBoxMonth;
 if(monthDiff > 10)
 {
  throwAlert();
 }
 else if(monthDiff == 10)
 {
  if(textBoxDay < thisDay)
   throwAlert();
 }
 //else OK
}
else if(thisYear - textBoxYear == 1)
{
 var monthDiff = (thisMonth + 12) - textBoxMonth;
 if(monthDiff > 10)
 {
  throwAlert();
 }
 else if(monthDiff == 10)
 {
  if(textBoxDay < thisDay)
   throwAlert();
 }
 //else OK
}
else
 throwAlert();

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top