?
???? ??????
???? ????? "Ron2005 said:To get the last day of the month, I have sometimes simply ADDED 1 month
to the date and then SUBTRACTED 1 day from the result.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
???? ????? "Ron2005 said:To get the last day of the month, I have sometimes simply ADDED 1 month
to the date and then SUBTRACTED 1 day from the result.
Bill said:I am trying to pass a date in code, add calculated months (from 1 -
7) to it and write the new date with the day field being the last day
of that month. I've read an ms document (#210604) showing how to use
the dateserial function. I've used it but am finding it is not
coming back with accurate dates! A variable should have been
returning 10/31/05 was coming back 10/30.05. I also had the same
thing happen in the month of August. It was coming back with 8/30/05
not 8/31/05. I tried different years, still happened. Here is my
code:
Dim amntMnths2 As Integer
amntMnths2 =
Int(Forms![deposit]![CashHistOrphans4Deposits]![ContrBaL] /
Forms![deposit]![CashHistOrphans4Deposits]![RegSend])
dtmDate =
Forms![deposit]![CashHistOrphans4Deposits]![PaidThru]
dhLastDayInMonth = DateSerial(Year(dtmDate),
Month(dtmDate) + 1, 0)
Forms![deposit]![CashHistOrphans4Deposits]![PaidThru] = DateAdd("m",
amntMnths2, _
dhLastDayInMonth)
I think the problem is in the "+1" (in the dateserial line), but I am
not sure, as the ms documentation says "for the next month" - it does
not say for as many months as you want to add. Any thoughts on this?
Thanks for sharing you experience and your time!
Rick Brandt said:Bill said:I am trying to pass a date in code, add calculated months (from 1 -
7) to it and write the new date with the day field being the last day
of that month. I've read an ms document (#210604) showing how to use
the dateserial function. I've used it but am finding it is not
coming back with accurate dates! A variable should have been
returning 10/31/05 was coming back 10/30.05. I also had the same
thing happen in the month of August. It was coming back with 8/30/05
not 8/31/05. I tried different years, still happened. Here is my
code:
Dim amntMnths2 As Integer
amntMnths2 =
Int(Forms![deposit]![CashHistOrphans4Deposits]![ContrBaL] /
Forms![deposit]![CashHistOrphans4Deposits]![RegSend])
dtmDate =
Forms![deposit]![CashHistOrphans4Deposits]![PaidThru]
dhLastDayInMonth = DateSerial(Year(dtmDate),
Month(dtmDate) + 1, 0)
Forms![deposit]![CashHistOrphans4Deposits]![PaidThru] = DateAdd("m",
amntMnths2, _
dhLastDayInMonth)
I think the problem is in the "+1" (in the dateserial line), but I am
not sure, as the ms documentation says "for the next month" - it does
not say for as many months as you want to add. Any thoughts on this?
Thanks for sharing you experience and your time!
For DateSerial to give you the last day of a given month you actually ask it
for the zeroth day of the next month. That is why you add one to the month
and use zero for the day argument so your current syntax is correct.
I didn't bother to figure out all of the other stuff that is going on with
your expression, but you are using DateSerial properly if you want the last
day of a month. Any time the last argument is zero you are guaranteed to
get the last day of "some" month. You are losing a day someplace else in
there.
Bill said:so you don't think the ms function could be wrong?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.