JavaScript

Javascript Add minutes to date Example

In this article, I am going to discuss about Javascript: Add minutes to date i.e how to add any number of minutes to a date.

Example to Add minutes to date using JavaScript

Here is a simple example that shows how to add minutes to date using JavaScript:

<script language="javascript" type="text/javascript">
//The current date
var date = new Date ();
//New/future date
var new_date = new Date ( date );
//Minutes to add_action. Change this as required
var minutes = 60;
//Add the minutes to current date to arrive at the new date
new_date.setMinutes ( date.getMinutes() + minutes );
//Output the old + new date
document.write('Old Date: ' + date + '<br /> New Date:' + new_date);
//Output is:
//Old Date: Thu Mar 08 2012 11:42:11
//New Date: Thu Mar 08 2012 12:42:11
//Note: The above values also shows the Timezone, but I have removed it for simplicity from the example

//If you do not want to show the current date but need to show only the new date, then this can be further simplified as:
var revised_date = new Date();
revised_date.setMinutes(revised_date.getMinutes() + minutes);
document.write('<br /> ' + revised_date);
//Output is Thu Mar 08 2012 12:42:11
</script>
Simple, isnt’ it?

Do you know of any other ways to Add minutes to date  using JavaScript? Feel free to suggest by commenting below.

Share your thoughts, comment below now!

*

*