pandian
asked on
date manipulation in javascript
I want to know date manipulation in javascript.
1. how to compare current date with the user date entry.
2. how to add current date with the string format.
For example "dd/mm/yyyy"
usrdate = "25/02/2000"
if( curdate > usrdate )
give some examples
thank you
1. how to compare current date with the user date entry.
2. how to add current date with the string format.
For example "dd/mm/yyyy"
usrdate = "25/02/2000"
if( curdate > usrdate )
give some examples
thank you
PS: You might want to change to this:
function compare(theForm)
theYear = theForm.theYear.options[th eForm.theY ear.select edIndex].v alue;
theMonth = theForm.theMonth.options[t heForm.the Month.sele ctedIndex] .value;
theDay = theForm.theMonth.options[t heForm.the Month.sele ctedIndex] .value;
if (theYear = '' || theMonth = '' ||theDay = '') {
alert('Please select year and month and day');
return false;
}
and have a return true at the end of the function:
return true;
}
</script>
function compare(theForm)
theYear = theForm.theYear.options[th
theMonth = theForm.theMonth.options[t
theDay = theForm.theMonth.options[t
if (theYear = '' || theMonth = '' ||theDay = '') {
alert('Please select year and month and day');
return false;
}
and have a return true at the end of the function:
return true;
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
I am using perl program to genarate the HTML with the embeded javascript. There I have to create multiple same data entry form. That each form on same the page should have three date entry field execpt others. So I can not use the option control. May be it takes more space on the page and loading time. so I leave it for text box.
Any way thanks for your coding. I will get some knowladge from you script. Keeping that I will mannage.
Thank you one again.
I am using perl program to genarate the HTML with the embeded javascript. There I have to create multiple same data entry form. That each form on same the page should have three date entry field execpt others. So I can not use the option control. May be it takes more space on the page and loading time. so I leave it for text box.
Any way thanks for your coding. I will get some knowladge from you script. Keeping that I will mannage.
Thank you one again.
Xabi, are you poaching???
Michel
Michel
Sorry michael, as you know I'm Spanish and my English is far from perfect. What's poaching? :)
xabi
xabi
Answering a question where a comment might be the answer
(poaching is when people go hunting where they are not allowed)
Michel
(poaching is when people go hunting where they are not allowed)
Michel
Ok, sorry. It was a crossposting. Sorry.
xabi
xabi
<FORM>
<SELECT NAME="theYear">
<OPTION VALUE="">Select a year
<OPTION VALUE="2000">2000
<OPTION VALUE="2001">2001
<OPTION VALUE="2002">2002
<OPTION VALUE="2003">2003
</SELECT>
<SELECT NAME="theMonth">
<OPTION VALUE="">Select a month
<OPTION VALUE="0">1
<OPTION VALUE="1">2
<OPTION VALUE="2">3
<OPTION VALUE="3">4
..
..
<OPTION VALUE="11">12
</SELECT>
<SELECT NAME="theDay">
<OPTION VALUE="">Select a day
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
<OPTION VALUE="4">4
..
..
<OPTION VALUE="31">31
</SELECT>
<input type="button" onClick="compare(this.form
and then use
<script>
/* Compare and calculate (c) 2000 Michel Plungjan */
function compare(theForm)
theYear = theForm.theYear.options[th
theMonth = theForm.theMonth.options[t
theDay = theForm.theMonth.options[t
userDate = new Date(theYear,theMonth,theD
testYear = userDate.getYear();
if (testYear<1000)testYear +=1900;
if (testYear != theYear ||
userDate.getMonth() != theMonth ||
userDate.getDay() != theDay) {
alert('Date is not correct');
return false;
now = new Date();
if (userDate.getTime() < now.getTime()) alert('Date must be later than today');
}
</script>
I apologise for any typo.
Michel