Javascript to calculate 7 days ago?

suavechoi

New member
Apr 6, 2011
75
0
0
Hope this isn't too big a deal to ask, here are some tits for help:

Hey Guys

So here's the code to calculate the various variables for today's date, how can I modify it so it calculates the date 7 days ago (last week)?


Code:
// Get today's current date.
var monthNames = new Array("1","2","3","4","5","6","7","8","9","10","11","12");
  var now = new Date();
  now.setDate(now.getDate());
 
// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('1','2','3','4','5','6','7','8','9','10','11','12');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
 return (number < 1000) ? number + 1900 : number;
        }

// Join it all together
today = 
       now.getDate()

// Print out the data.
returnValue = today;

1304370220072.gif


79%20Great%20Tits.jpg
 


This line:

Code:
now.setDate(now.getDate());
To this:
Code:
now.setTime(1000 * 60 * 60 * 24 * 7 * (-1));
Should subtract a week's worth of milliseconds from current time.