By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,819 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,819 IT Pros & Developers. It's quick & easy.

Validating Date

100+
P: 110
I want to take the date from user as
MONTHYY ----MAR08,FEB08

how do i do thisalso how i add months to the date (yyyy-mm-dd format and get a new date)



thanks in advance
Mar 5 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
For validating that, just have an array of the months ("JAN", "FEB", "MAR", etc.) and check that the first three characters (using substring()) are one of the months. Then check that the last two are digits.

To add months, just use setMonth with the current month (getMonth()) + how many months you want to add.
Mar 5 '08 #2

100+
P: 110
Thanks i did this with pph array for motnhs to give the help to user to select in the format
JAN08 etc
but now i want to check two dates given in this format
say dt1='MAR08'
dt2='JAN10'

I want to check if dt1> dt2 or viceversa
and if it is greater then alert and stop the user to go to the next field

how do i do this in javascript



Thanks
Mar 6 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You need to use the Date() object. The dates need to be set in a Date object and then comparing is easy. To set the month, use an array of months and loop over until the correct month is found and that would be the number to pass to setMonth(). Use setFullYear() for the year with "20" appended. You could use setFullYear() for both - see this link.
Mar 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.