Friday, 7 October 2011

Calculate last date of given month using JavaScript

<html>
<body>
The end date of this month is
<script type="text/javascript">


//Today
var d = new Date();

//var d = new Date(2011, 10, 1);
//alert(d);

//End date of this month
var d = new Date(d.getFullYear(), d.getMonth() + 1, 0);

//alert(d);

var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December' ];
var endDate = d.getDate() + ' ' + monthNames[d.getMonth()] + ' ' + d.getFullYear();

//alert(endDate);

document.getElementById('prizeDrawEndDate').innerHTML = endDate;

</script>




Click here to try it by copying the script into w3schools try it editor

No comments:

Post a Comment