Documentation and Books

Recent site activity

Web Development‎ > ‎JavaScript‎ > ‎

How do i add a number of days to a date?

The following JavaScript method provides this functionality:

<html>
<head>
<script language="JavaScript">
function addDays(date, days) {
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
}
</script>
</head>
<body>
<input type="button" value="Display 01-01-2007 plus 7 days" onclick="alert(addDays(new Date(2007, 01, 01), 7));"/>
</body>
</html>

Notice that you have to pass a Date object into the addDays method and not String values.