date comparisons

1. Senior Member
Join Date
Dec 1969
Posts
113

## date comparisons

I am trying to compare 2 month values to see if one is less than the other. one of the values is entered into a text field by the user. the other I get the current month from the system. how do I convert the number that is entered into the text box into a valid month for comparison. or how do I get them in the same format ofr comparison in javascript.<BR><BR>Thanks,<BR><BR>Bill

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: date comparisons

Two month values? If they&#039;re just months, then surely you don&#039;t care - they&#039;re just numbers...?<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
113

## RE: date comparisons

heres what happens when I say if emonth &#060; cumonth then<BR>whatever. if emonth =10 and curmonth=5 it sees emonth as less than curmonth. if I was using just vbscript to do my comparison I would say if cint(emonth) &#060; cint(curmonth) etc. but how do I do that in javascript. I have never had to do that before.<BR><BR>Bill

4. Senior Member
Join Date
Dec 1969
Posts
113

## found it

I did not realize that if javascript can performa a mathmatical operation on something it treats it as a number. so I just did this.<BR><BR>e=&#039;10&#039;<BR>curmo = 5<BR><BR>e2=e * 1;<BR><BR>e2 is then = 10<BR><BR>if e2 &#060; curmo<BR> works correctly for all months<BR><BR>I found this on the following website:<BR><BR>http://www.quirksmode.org/

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Ugh...works but...

...a better solution is parseInt or parseFloat<BR><BR>if ( parseInt(e) &#060; curmo ) ...<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
113

## RE: Ugh...works but...

I do like that better and will use it in the future. Iam really just starting to do alot of Javascript and you and reaperman have been very helpful. I should probably send you guys some money for all of the help you have given me the last couple of weeks. That is almost like what i would use in vbscript.<BR><BR>Thanks,<BR><BR>Bill

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Ugh...works but...

I dunno about Bill, but I don&#039;t take any money for help through here.<BR><BR>That said, if you are feeling generous and wish to donate a small amount for help, I am trying to drum up support for this charity:<BR>http://www.janesappeal.com<BR><BR>It&#039;s on behalf of this remarkable woman:<BR>http://www.bbc.co.uk/leeds/features/jane_tomlinson/jane_route.shtml<BR><BR>If you fancy dropping \$5 or something in there, I know a lot of people would be grateful.<BR><BR>(The charity above is not related to me, or to this board. This is my opinion, and doesn&#039;t reflect the opinions of this board, its parent companies, or moderators.)<BR><BR>Sorry, just thought I needed that disclaimer. It&#039;s a good cause that I&#039;ve been following recently.<BR><BR>Craig.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•