var myEndDateTime = somedate; //somedate is a valid js date
var durationInMinutes = 100; //this can be any number of minutes from 1-7200 (5 days)
//this is the calculation I don't know how to do
var myStartDate = somedate - durationInMuntes;
alert("The event will start on " + myStartDate.toDateString() + " at " + myStartDate.toTimeString());
Once you know this:
Dateby calling the constructor with milliseconds since Jan 1, 1970.
Dateis the number of milliseconds since Jan 1, 1970
60,000milliseconds in a minute :-]
...it isn't so hard.
In the code below, a new
Date is created by subtracting the appropriate number of milliseconds from
var MS_PER_MINUTE = 60000; var myStartDate = new Date(myEndDateTime - durationInMinutes * MS_PER_MINUTE);