
Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following 1. Display the day no from the date 2. Display the year from the date 3. Display the month from the date 4. Change the date to next day 5. Change the year to next year 6. change the month to next month

<html>
<script type="text/javascript">
function checkdate(){
var input=document.getElementById('mydate');
var validformat=/^\d{2}\/\d{2}\/\d{4}$/
var returnval=false
if(!validformat.test(input.value))
alert("Invalid Date Format!")
else{
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
document.getElementById("no").value=dayfield;
document.getElementById("month").value=monthfield;
document.getElementById("year").value=yearfield;
document.getElementById("nextno").value=parseInt(dayfield)+1;
document.getElementById("nextmonth").value=parseInt(monthfield)+1;
document.getElementById("nextyear").value=parseInt(yearfield)+1;
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range!")
else
returnval=true
}
if(returnval==false) input.select()
return returnval
}
</script>
Enter date (mm/dd/yyyy):<input type="text" id="mydate" />
<input type="button" value="submit" onclick="checkdate();"><br />
<pre>
Day No <input type="text" id="no">
Month <input type="text" id="month">
Year <input type="text" id="year">
Next Day <input type="text" id="nextno">
Next Month <input type="text" id="nextmonth">
Next Year <input type="text" id="nextyear">
</pre>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.