I'm wondering if someone can help me. I'm trying to output the Day, Month, Date and Year but I'm getting into a spot of bother. I think I'm close, but just need to nail this one last part. My script is this.
Code:
function addDaysToDate(days) {
var day = new Array("Mon","Tue","Wed","Thur","Fri","Sat","Sun");
var mths = new Array("Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec");
var d = new Date();
d.setHours(d.getHours() + (24 * days));
var currDa = d.getDay();
var currD = d.getDate();
var currM = d.getMonth();
var currY = d.getFullYear();
return day [currDa] + " ," + currM + " " + currD + ", " + currY;
}
It was working fine with the months but I wanted to add the days and it's all gone to pot, can someone help me please. Thanks.
Days in Javascript run from Sunday (0) to Saturday (6).
Code:
<script type="text/javascript">
function addDaysToToday( numDays ) {
var date = new Date();
date.setDate( date.getDate() + numDays );
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var day = ["Sun", "Mon","Tue","Wed","Thur","Fri","Sat"];
var dy = date.getDay();
return day[dy] + " " + months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();
}
alert (addDaysToToday(7));
// To subtract days from today, just pass a negative number to the function.
</script>
One of the opposums was St.Matthew who was also a taximan.
- Pupil's answer to Catholic Elementary School test.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.