PDA

View Full Version : 30 days from today


landon11
05-01-2003, 05:22 PM
how do find out what the date was 30 days ago?

raf
05-01-2003, 06:45 PM
By using the datediff() function. More info, see below

For your question, use:

DateAdd("d",30,Now)

But if you need the date one month from now, you probably should better use

DateAdd("m",1,Now)

more info from helpfile
----------------------------------
Description
Returns a date to which a specified time interval has been added.
Syntax
DateAdd(interval, number, date)
The DateAdd function syntax has these parts:

Part Description
interval Required. String expression that is the interval you want to add. See Settings section for values.
number Required. Numeric expression that is the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past.
date Required. Variant or literal representing the date to which interval is added.


Settings
The interval argument can have the following values:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second


Remarks
You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now. To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").
The DateAdd function won't return an invalid date. The following example adds one month to January 31:

NewDate = DateAdd("m", 1, "31-Jan-95")

In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.
If the calculated date would precede the year 100, an error occurs.

If number isn't a Long value, it is rounded to the nearest whole number before being evaluated.

landon11
05-01-2003, 09:53 PM
Thank you, I knew about DateDiff but not DateAdd. This is how I use it

myDate = DateAdd("d", -30, Now)

raf
05-01-2003, 10:33 PM
Ah, yeah. It was 30 days ago (didn't read your post carefully enough), so indeed, you need to substract.