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 4 10005
That's a feature. The function, when using the "m" argument, simply moves
you back one month (changes April to March, for example) without changing
the day portion. If that produces an invalid date (such as February 31), it
then goes to the first valid date earlier than the invalid one being
"calculated".
To get the first day of a month (represented by MonthInteger):
DateSerial(YearInteger, MonthInteger + 1, 0)
Thus, to get the first day of the current month (using Date() function for
the current date):
DateSerial(Year(Date()), Month(Date())+1, 0)
--
Ken Snell
<MS ACCESS MVP>
<ey*******@iname.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... 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 ey*******@iname.com wrote in
news:11**********************@o13g2000cwo.googlegr oups.com: 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?
If I test:
DateAdd("m", 1, "28-Feb-05")
I get 3/28/2005., not 1/28/2005, as you say.
DateAdd("m", -1, "28-Feb-05") gives me 1/28/2005. So, you really
need to check the formula in your report.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
"Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in
news:AP********************@comcast.com: That's a feature. The function, when using the "m" argument, simply moves you back one month (changes April to March, for example) without changing the day portion. If that produces an invalid date (such as February 31), it then goes to the first valid date earlier than the invalid one being "calculated".
To get the first day of a month (represented by MonthInteger): DateSerial(YearInteger, MonthInteger + 1, 0)
Thus, to get the first day of the current month (using Date() function for the current date): DateSerial(Year(Date()), Month(Date())+1, 0)
Um, that returns the last day of the current month.
To get the 1st day of the current month, you need only:
DateSerial(Year(Date()), Month(Date()), 1)
Or, a simpler way:
DateValue(Format(Date(),"mm/yyyy"))
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Absolutely correct-o, David. Thanks for the catch. Musta had my mind on
something other than my work....
--
Ken Snell
<MS ACCESS MVP>
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.90... "Ken Snell" <kt***********@ncoomcastt.renaetl> wrote in news:AP********************@comcast.com:
That's a feature. The function, when using the "m" argument, simply moves you back one month (changes April to March, for example) without changing the day portion. If that produces an invalid date (such as February 31), it then goes to the first valid date earlier than the invalid one being "calculated".
To get the first day of a month (represented by MonthInteger): DateSerial(YearInteger, MonthInteger + 1, 0)
Thus, to get the first day of the current month (using Date() function for the current date): DateSerial(Year(Date()), Month(Date())+1, 0)
Um, that returns the last day of the current month.
To get the 1st day of the current month, you need only:
DateSerial(Year(Date()), Month(Date()), 1)
Or, a simpler way:
DateValue(Format(Date(),"mm/yyyy"))
-- David W. Fenton http://www.bway.net/~dfenton dfenton at bway dot net http://www.bway.net/~dfassoc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gabe |
last post by:
Please see: http://www.showorders.com/test3.asp
The code generating the page is as follows:
testdate = "1/29/2003 1:00:00 PM"
while count...
|
by: Zlatko Matić |
last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the
function that is calculating next date of sampling...
In MSDE there is a...
|
by: Abdul N K |
last post by:
I need help in T-SQL.
I am using DATEADD function and I want to add 6 months to a date. But
it does not return me the rusults, which I want
...
|
by: C.Davidson |
last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to
implement the following without success. In my example I tried to
simply add 30...
|
by: Zlatko Matić |
last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the
function that is calculating next date of sampling...
In MSDE there is a...
|
by: Rich Raffenetti |
last post by:
I have the following code. If I do the dateadd function with
dateinterval.minute, it works fine and the date/time value is displayed with
zero...
|
by: kevinSQL |
last post by:
Is it possible to dynamically modify the Datepart argument of the DATEADD function in T-SQL 2005.
I am trying to do something like this but it's...
|
by: rodrigo21 |
last post by:
Hello,
I have one form with a field for entering a date 'orderdate' and another field for entering a days interval 'range'.
This form is used to...
|
by: Mel |
last post by:
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
| |