Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Adobe, I've used this to calculate the current date:
var myfield=getField("datebox");

var date=new Date();

date=util.printd("mmm dd yyyy, h:MM tt", date);

myfield.value=date;


I need to be able to take that date and calculate the date X days before.

I am a total newb, appreciate any help.

What I have tried:

I've tried inserting random -7 (for seven days prior), but I'm a total newb, so really I have no idea what to try.
Posted
Updated 26-Feb-18 3:33am
Comments
A_Griffin 25-Feb-18 16:02pm    
I'm not normally a fan of "black box" solutions, but dates are a pain in the derriere in JS, so I'd recommend using moment.js: https://momentjs.com/
Karthik_Mahalingam 26-Feb-18 0:29am    
what do you want to calculate?

1 solution

Add days to JavaScript Date - Stack Overflow[^]
JavaScript
Date.prototype.addDays = function(days) {
    var dat = new Date(this.valueOf());
    dat.setDate(dat.getDate() + days);
    return dat;
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900