Javascript Data Type How to - Add 1 day with an given date








Question

We would like to know how to add 1 day with an given date.

Answer


<!--from www  .  ja  v a2 s.  c o m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){
    var incept_dt = "2014-01-05".split("-");
    var in_date = new Date(incept_dt[0], incept_dt[1], incept_dt[2])
    in_date.setDate(in_date.getDate() + 1)
    var yy = in_date.getFullYear();
    var mm = in_date.getMonth() + 1;
    var dd = in_date.getDate();
    var final_Date = yy + "-"+ mm + "-"+ dd; 
    document.writeln(final_Date)
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: