473,809 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference in months

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.

Any help with this would be appreciated.

Thanks!

Jul 23 '05 #1
7 2337
br********@gmai l.com wrote:
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.


A good start is to have a read here:

<URL:http://www.merlyn.demo n.co.uk/js-dates.htm>

--
RobG
Jul 23 '05 #2
<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
Jul 23 '05 #3
I'll give it a shot. Thanks for your help!

Jul 23 '05 #4
br********@gmai l.com wrote:
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.

Any help with this would be appreciated.

Consider that a month is an imprecise measurement, here in NY there are
at least 6 different month "lengths". And this disregards year end
tweakings of the "atomic" clock.

Mick
Jul 23 '05 #5
JRS: In article <FE************ ****@news2.mts. net>, dated Wed, 1 Jun
2005 15:39:17, seen in news:comp.lang. javascript, Grant Wagner
<gw*****@agrico reunited.com> posted :


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): (anotherDay.get FullYear() - today.getFullYe ar()) * 12 +
(anotherDay.get Month() - today.getMonth( ))

One can also calculate an "Absolute Month Number" like
function AWM(Y, M) { return Y*12+M }
and then subtract. It's numerically equivalent, and less efficient; but
the concept can be helpful in more complicated cases.

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.
Necessary but not sufficient. It is also necessary that new Date(), for
all users, interprets it in the same way as the user expects. And that
must be tested for the Nth of month M, where N != M and N < 13.


In article <gL************ **@twister.nyro c.rr.com>, dated Wed, 1 Jun
2005 16:54:36, seen in news:comp.lang. javascript, Mick White <mwhite13BO
GU*@rochester.r r.com> posted :
Consider that a month is an imprecise measurement, here in NY there are
at least 6 different month "lengths". And this disregards year end
tweakings of the "atomic" clock.


And Lunar, Hebrew, Islamic, etc., months.

Year middle tweakings are equally favoured, and have been approximately
equally common. Tweakings at the end of odd quarters are also allowed,
but less favoured, and have not so far been needed.

There will be none at the end of this month; but the length of time
since the previous leap second now is and until the next one will remain
longer than it has ever been before (IIRC).

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #6
Mick White wrote:
br********@gmai l.com wrote:

Consider that a month is an imprecise measurement, here in NY there
are at least 6 different month "lengths". And this disregards year end
tweakings of the "atomic" clock.
6 different month lengths !!

Thats beyond my schoolknowledge or are we using a different calendar in
Denmark 8-)

Mick

Jul 23 '05 #7
please-answer-here wrote:
Mick White wrote:

<snip>
Consider that a month is an imprecise measurement, here
in NY there are at least 6 different month "lengths". And
this disregards year end tweakings of the "atomic" clock.


6 different month lengths !!

Thats beyond my schoolknowledge or are we using a different
calendar in Denmark 8-)


That sounds about right. 4 Obvious differences in the length of months
in days and two months containing daylight savings/summer time
adjustments.

Richard.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4494
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the difference. I want it to return the difference in years, months, days, hours, minutes and seconds (a complete summary). Keeping into account of course that these are 2 real dates, I dont want it to work with 30.475 as an average number of days in a...
2
1512
by: Bill | last post by:
I need an ASP routine that will take a date, compare it to the present date, and then output the difference in Years, Months, and Days. (I'm too swamped to write it myself & I'm sure somebody already wrote it better than I can) If anyone can point me towards such a routine, I'd appreciate it. Thanks,
26
4425
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: starttime = Date.parse("Aug 10,2003, 07:07") sdt = new Date(starttime)
5
2166
by: tamilan71 | last post by:
Hello All I have table with following fields: GroupId VisitDate 1 10/19/1993 1 11/24/1998 2 10/18/1993 2 10/29/1998 3 10/21/1993
5
19409
by: Ali Baba | last post by:
Hi, Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. Docs says that I can use TimeSpan like: TimeSpam ts = date1 - date2; but this gives me data in Days. I don't want to divide this number by 30 because not every month is 30 days and since the two operand values are
6
77860
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From which I can get the duration in days, hours and so.. but how can I get the difference in months? Please reply ASAP. it's urgent. -- regards, Ashish Sheth
23
14070
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that didn't work (the timedelta class doesn't have a year accessor). I looked in the docs and the cookbook, but I couldn't find anything, so
3
2111
by: bootzwiz | last post by:
How can we find months difference between two dates. For Exp : Start Date : 05/03/2007 End Date : 06/10/2007 How to calucate months difference for any dates?.
4
6664
by: sniipe | last post by:
Hi! I am new in Python, so I count for your help. I need to get difference in months between two dates. How to do it in python? I am substracting two dates, for example date1 - date2 and I got result in days, how to change it? Best regards
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.