Greetings,
I have an A2K application where for a report the user enters a
month-end date, and the system must gather transactions for that month.
No problem, I thought, I'll just use the DateAdd function for the
beginning of the date range, like this:
Between DateAdd("m",-1,[Forms]![frmMonthlyRpt]![txtRptDate]) And
[Forms]![frmMonthlyRpt]![txtRptDate]
After all, Microsoft's documentation states:
-------------------------
DateAdd Function
Returns a date to which a specified time interval has been added.
Arguments
interval
Required. String expression that is the interval you want to add.
See Settings section for values.
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
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.
-------------------------
That's all fine and well, but I find that the function produces the
following results:
When txtRptDate is 1/31/05, it returns 12/31/05.
For 2/28/05 it returns 1/28/05.
For 3/31/05 it returns 2/28/05.
So it looks like it subtracts the number of days in the month supplied
- which would work fine for me (if I add +1 to the DateAdd result),
except in February, when it subtracts 30 days!
I wonder if this is a bug or a feature. Would anyone have a
work-around, please?
Thanks,
Yisroel
I have an A2K application where for a report the user enters a
month-end date, and the system must gather transactions for that month.
No problem, I thought, I'll just use the DateAdd function for the
beginning of the date range, like this:
Between DateAdd("m",-1,[Forms]![frmMonthlyRpt]![txtRptDate]) And
[Forms]![frmMonthlyRpt]![txtRptDate]
After all, Microsoft's documentation states:
-------------------------
DateAdd Function
Returns a date to which a specified time interval has been added.
Arguments
interval
Required. String expression that is the interval you want to add.
See Settings section for values.
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
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.
-------------------------
That's all fine and well, but I find that the function produces the
following results:
When txtRptDate is 1/31/05, it returns 12/31/05.
For 2/28/05 it returns 1/28/05.
For 3/31/05 it returns 2/28/05.
So it looks like it subtracts the number of days in the month supplied
- which would work fine for me (if I add +1 to the DateAdd result),
except in February, when it subtracts 30 days!
I wonder if this is a bug or a feature. Would anyone have a
work-around, please?
Thanks,
Yisroel
Comment