|
-
May 11th, 2004, 01:21 PM
#1
Thread Starter
Hyperactive Member
Validate Same Month
How can I validate in Javascript that two dates are within the same month without comparing the first two characters of the date string (i.e. 05/11/2004)?
A cynic knows the price of everything but the value of nothing.
-
May 11th, 2004, 02:27 PM
#2
Frenzied Member
what form is the input in?
if it is dd/mm/yyyy or mm/dd/yyyy, then you have to compare the mm to the other mm. Of course there are more and less efficient ways to do this.
Here's how I'd do it.
Code:
date1 = "24/02/1986"
date2 = "11/05/2004"
Ar1 = new Array()
Ar2 = new Array()
Ar1 = split(date1,"/")
Ar2 = split(date2,"/")
if (Ar1[1] == Ar2[1])
{
//Same month
}
Have I helped you? Please Rate my posts. 
-
May 12th, 2004, 03:19 AM
#3
Dredging up a memory of javascript, there is a date type. If you can get the entered date into it I think there is a property or method of .month()
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
May 12th, 2004, 06:08 AM
#4
Frenzied Member
Code:
//To get the current month:
now = new Dat()
current_month = now.getMonth()
That will get you the current month, but this isn't very useful for comparing two dates. It could be if one of the dates is always todays date I suppose. You'll still have to use the mm from dd/mm/yyyy from the other date though.
If you're simply trying to compare two dates, use the code I supplied in the first post.
Have I helped you? Please Rate my posts. 
-
May 12th, 2004, 10:06 AM
#5
Code:
//To get the current month:
now = new Dat()
current_month = now.getMonth()
Following on...
Code:
strDate1 = "24/02/1986"
strDate2 = "11/05/2004"
// dunno if this works? or how it copes with american/english date formats
dte1 = strDate1.toDate()
dte2 = strDate2.toDate()
if (dte1.getMonth() == dte2.getMonth()) {
//do whatever
}
But hey its your choice, we are just providing options 
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|