Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
'************************************************* *************************
' Accepts a date. Determines month & year of the date. Returns
' the date of the last day of that month (in the same year)
'************************************************* *************************
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of 6/15/2005, the FN returns 7/1/2005 instead
of 6/30/2005. What's wrong? 7 6011
MLH wrote: Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************* ************************* ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************* ************************* GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of 6/15/2005, the FN returns 7/1/2005 instead of 6/30/2005. What's wrong?
Not all months have 31 days. Use...
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
DateSerial is smart enough to know that the zeroth of a month is equal to the
last day of the previous month regardless of how many days are in that month.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
That's pretty sneaky, Rick. I like it. Thx a bunch. GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
On Sun, 10 Jul 2005 19:23:00 GMT, "Rick Brandt" <ri*********@hotmail.com>
wrote: MLH wrote: Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************* ************************* ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************* ************************* GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of 6/15/2005, the FN returns 7/1/2005 instead of 6/30/2005. What's wrong?
Not all months have 31 days. Use...
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
DateSerial is smart enough to know that the zeroth of a month is equal to the last day of the previous month regardless of how many days are in that month.
That works, but it's very confusing to understand how. Here's another method
that takes more code, but I like it better anyway...
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
Dim dtFirstOfMonth As Date
dtFirstOfMonth = DateAdd("d", 1 - Day(tdDay), tdDay)
Dim dtFirstOfNextMonth As Date
dtFirstOfNextMonth = DateAdd("m", 1, dtFirstOfMonth)
GetLastDayOfMonth = DateAdd("d", -1, dtFirstOfNextMonth)
End Function
"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:n5********************************@4ax.com... On Sun, 10 Jul 2005 19:23:00 GMT, "Rick Brandt" <ri*********@hotmail.com> wrote:
MLH wrote: Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************* ************************* ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************* ************************* GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of 6/15/2005, the FN returns 7/1/2005 instead of 6/30/2005. What's wrong?
Not all months have 31 days. Use...
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
DateSerial is smart enough to know that the zeroth of a month is equal to the last day of the previous month regardless of how many days are in that month.
That works, but it's very confusing to understand how. Here's another method that takes more code, but I like it better anyway...
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
Dim dtFirstOfMonth As Date dtFirstOfMonth = DateAdd("d", 1 - Day(tdDay), tdDay)
Dim dtFirstOfNextMonth As Date dtFirstOfNextMonth = DateAdd("m", 1, dtFirstOfMonth)
GetLastDayOfMonth = DateAdd("d", -1, dtFirstOfNextMonth) End Function
If it's wrapped in a function, I don't see what it matters if not everyone
understands how it works. The name of the function makes it obvious what
it's supposed to be doing.
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
End Function
--
Doug Steele, Microsoft Access MVP http://I.Am/DougSteele
(no e-mails, please!)
Steve Jorgensen <no****@nospam.nospam> wrote: On Sun, 10 Jul 2005 19:23:00 GMT, "Rick Brandt" <ri*********@hotmail.com> wrote:
MLH wrote: Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************* ************************* ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************* ************************* GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31)
End Function
If I enter dtDay value of 6/15/2005, the FN returns 7/1/2005 instead of 6/30/2005. What's wrong?
Not all months have 31 days. Use...
GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay) + 1, 0)
DateSerial is smart enough to know that the zeroth of a month is equal to the last day of the previous month regardless of how many days are in that month.
That works, but it's very confusing to understand how. Here's another method that takes more code, but I like it better anyway...
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date
Dim dtFirstOfMonth As Date dtFirstOfMonth = DateAdd("d", 1 - Day(tdDay), tdDay)
Dim dtFirstOfNextMonth As Date dtFirstOfNextMonth = DateAdd("m", 1, dtFirstOfMonth)
GetLastDayOfMonth = DateAdd("d", -1, dtFirstOfNextMonth) End Function
I use.....
LastDayOfMonth = DateAdd("d", -1, DateSerial(Year(myDate), Month(myDate)
+ 1, 1))
--
regards,
Bradley
A Christian Response http://www.pastornet.net.au/response
Br@dley wrote: I use.....
LastDayOfMonth = DateAdd("d", -1, DateSerial(Year(myDate), Month(myDate) + 1, 1))
But why have the overhead of running two functions when DateSerial is perfectly
capable of doing this by itself?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Rick Brandt <ri*********@hotmail.com> wrote: Br@dley wrote: I use.....
LastDayOfMonth = DateAdd("d", -1, DateSerial(Year(myDate), Month(myDate) + 1, 1))
But why have the overhead of running two functions when DateSerial is perfectly capable of doing this by itself?
I was just saying that _was_ how I did it compared to the several lines
of code used in the previous post. Obviously now I know zero has the
same effect I'll use that.
--
regards,
Bradley
A Christian Response http://www.pastornet.net.au/response This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sugaray |
last post by:
hi, below is my program for doing exercise with library time functions,
something is not right with it, and for the time being i couldn't figure
out what's wrong and where, thanx for your help.
...
|
by: questions? |
last post by:
I am testing a problem with linked list.
I just do a lot of times: create a list, then free it.
#############################################
# include <stdio.h>
# include <stdlib.h>
struct...
|
by: Benny Ng |
last post by:
Dear All,
Modify1("SqlServer", "xxxxxxxxxxxxxx");
The error message is program can't find the XML segment <add
name="SqlServer" , But it seems should be runs properly. What's wrong with
the...
|
by: Paulo da Silva |
last post by:
Hi!
What's wrong with this way of subclassing?
from datetime import date
class MyDate(date):
def __init__(self,year,month=None,day=None):
if type(year) is str:
# The whole date is here as...
|
by: anniebai |
last post by:
Please help me with this RowUpdating function.
I copied it from the internet and modified the part that I could understand. and not surprisingly, it's not working.
When I tried to update a row,...
|
by: fl |
last post by:
Hi,
I am learning C++ with C++ primer written by Lippman. The first output
line: cout << s1 << endl; works right. The second is wrong. I find the
problem is that s1 is destroyed in the call from...
|
by: yaoc1987 |
last post by:
hello everyone
im writing a program for "sequence class with dynamic arrays"
every time i compile it gives me this error:
i believe all 3 is the same
to use copy i know i have to include...
|
by: yaoc1987 |
last post by:
my assignment was to implement a sequence class with dynamic array
for some reason the only error is this:
1>c:\documents and settings\joe\desktop\spring 2010\csc 212\hw\hw #3\sequence2.cxx(53) :...
|
by: flower88 |
last post by:
Hello,
I'm trying to get rid of duplicate entries for contacts. So in my contact entry form when the save buttom is clicked I want to use the DCount function to see if there are duplicates. Here...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |