Saturday, August 25, 2007

Javascript get current date to next date or previous date

Javascript get current date to next date or previous date
code:
--------------
<script>
<!--
datecount=27;
var cur_dat=new Date();
curdate=cur_dat.getDate();
var diff_dat=new Date();
diff_dat.setDate(curdate-datecount);
//dat.setMonth(5);
alert(diff_dat.getMonth()+"|"+diff_dat.getDate()+"|"+diff_dat.getYear());
-->
</script>
--------------
assign the value differ for date count
datecount=27;
Initalizing cur_dat date
var cur_dat=new Date();
Here i am assigning the the current date value in the variable curdate
curdate=cur_dat.getDate();
Now initalizing new date for date difference 'diff_dat'
set the date difference depends upon previous and next using Arithmetic
operation '-' and '+'.
diff_dat.setDate(curdate-datecount);
now Display or assign your new previous/next date accroding to your
operation

Tips:
By this method the reduction or addition of date will automatically change
next Month and year.Same way try for Month and year depends upon the
operation.

3 comments:

Adobe News