Jump to content

[SOLVED] add 50 days to current date in this format MM/DD/YYYY


solarisuser

Recommended Posts

Hello,

 

I am trying to have JavaScript read "09/04/2007" as a date value, and add 50 days to it.  Do I need to split it up into a different date format?  I tried adding parseInt(50) but it didnt automatically know what I'm trying to do.

 

Any help would be appriciated - thanks!

I think this will do what you want:

<script type="text/javascript">
var dateStr = "09/04/2007";
var millis = Date.parse(dateStr);
var newDate = new Date();
newDate.setTime(millis  + 50 *24*60*60*1000);
var newDateStr = "" + (newDate.getMonth()+1) + "/" + newDate.getDate() + "/" + newDate.getFullYear();
alert(newDateStr);
</script>

 

Hope it helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.