Get last week and next week days from current date javascript date object

by Jayanthi 2012-06-05 17:45:34

Get last week and next week days from current date javascript date object

JavaScript increments to the next month or year as required.

For example:

Today is the 5th of June and you add 7 days, it correctly sets the date to June 12.

<script type="text/javascript">

var myDate = new Date();

for(i=1;i<=7;i++)
{
myDate=new Date();
myDate.setDate(myDate.getDate() + i);
myDate.setHours(0, 0, 0, 0);
document.writeln(myDate+"<br>");

}

</script>

JavaScript decrements to the next month or year as required.

For example:

Today is the 5th of June and you add 7 days, it correctly sets the date to May 29.

<script type="text/javascript">

var myDate = new Date();

for(i=1;i<=7;i++)
{
myDate=new Date();
myDate.setDate(myDate.getDate() - i);
myDate.setHours(0, 0, 0, 0);
document.writeln(myDate+"<br>");

}

</script>
1112
like
0
dislike
0
mail
flag

You must LOGIN to add comments