<br********@gma il.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I was hoping someone could help me with this.. I'm not very familiar
with javascript but I'm pretty sure it can help me with what I need to
accomplish. I've tried piecing several pieces of script together but
I've had no luck so far.
What I need to do is have a user input for Year, Month and day
(preferably drop down) and compare the input to today's date and
display the difference in months.
I think you'll need to be more specific in terms of your requirements.
Assuming today is June 1.
If I enter June 2, how many "months" different is that from today? 0
months different? 0.0333333... months (1 day divided by the 30 days in
this month) different?
How about if I enter July 31? Is that 1 month different, 2 months
different (since July 31 is more than twice the number of days in June
away from June 1) or 2.0322580645161 290322580645161 29032 months
different (2 times 30 days in June + 1/31 days in July)?
I'm not trying to be difficult, when you say "how many months away is
this day from this other day" these are the types of real things you
need to think about.
Anyway, if you just want it as an integer where a day in the same month
is 0 months and any day in any other month is the number of months
different, then it's (something like):
<script type="text/javascript">
var today = new Date();
var anotherDay = new Date('May 6, 2006');
alert(Math.abs(
(anotherDay.get FullYear() - today.getFullYe ar()) * 12 +
(anotherDay.get Month() - today.getMonth( ))
));
</script>
But you've still got some problems... the date the user enters may not
be in a format that new Date() understands, so you'll need to parse it
and ensure that it is.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ -
http://jibbering.com/faq