P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Date
:
Date for 'n' days from some date.
author:
sxdesign
[+]
,
Submitted: 02.27.03 6a
• Last Edit: 02.27.03 7a
Date.prototype.getDateOffset = function(offset) { var retDate = new Date(this); retDate.setTime(retDate.getTime()+offset*86400000); // 86400000 represents a number of milliseconds each day haves return retDate; }
usage
This is a very simple function that will give you a date object for ANY day offset from current date (or from any other date object). I've noticed that a lot of people are asking me about this, so I thought I should write it somewhere... Usage is quite simple, as usual :) newDateObject = oldDateObject.getDateOffset(-5); this function will set a newDateObject to a date object, that holds data of 5 days ago from the oldDateObject... Or by example: [code] oldDateObject = new Date(); // getting current system date trace("20 days ago was: " + oldDateObject.getDateOffset(-20)); trace("Yesterday was: " + oldDateObject.getDateOffset(-1)); trace("Today is: " + oldDateObject.getDateOffset(0)); trace("Tomorrow will be: " + oldDateObject.getDateOffset(1)); trace("For 5 days will be: " + oldDateObject.getDateOffset(5)); [/code] This will return something like (this will hardly be the same at your place, but you get the picture): 20 days ago was: Fri Feb 7 15:11:19 GMT+0100 2003 Yesterday was: Wed Feb 26 15:11:19 GMT+0100 2003 Today is: Thu Feb 27 15:11:19 GMT+0100 2003 Tomorrow will be: Fri Feb 28 15:11:19 GMT+0100 2003 For 5 days will be: Tue Mar 4 15:11:19 GMT+0100 2003 hope it helps...
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@