Get todays date in mm/dd/yyyy format

Madhu.B.Rokkam
Posted by Madhu.B.Rokkam under JavaScript category on | Points: 40 | Views : 1896
A simple javascript code to return todays date

<script language = "javascript" type="text/javascript">

function today() {
var todaysDate = new Date();
var month = todaysDate.getMonth() < 9 ? ("0" + (parseInt(todaysDate.getMonth()) + 1)) : parseInt(todaysDate.getMonth()) +

1;
var day = todaysDate.getDate() < 10 ? "0" + todaysDate.getDate() : todaysDate.getDate();
return month + "/" + day + "/" + todaysDate.getYear();
}

alert(Date()); //Actual
alert(today()); //Formatted

</script>

Comments or Responses

Login to post response