Well, the first day of the month is surprisingly, 1.
Sorry, I couldn't resist.
You can return the weekday by using:
WeekDay(TheDate)
Now, to get the last day of the month use:
(replace TheDate with a date variable or the Date() function)
= Day(DateSerial(Year(TheDate), Month(TheDate) + 1, 0)) *******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
= Day(DateSerial(Year(TheDate), Month(TheDate) + 1, 0)) *******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
Isn't
= Day(DateSerial(Year(TheDate), Month(TheDate) + 1, 0))
going to return the first day of next month. You need
= Day(DateSerial(Year(TheDate), Month(TheDate) + 1, 0) -1 )
mattKnight : That's ok. I made plenty of mistakes yesterday as well - wasn't my day - and I often kick myself for not seeing the obvious, even when I have plenty of code using the same methods.
One could use the DateAdd function (get the first day of the following month and the subtract one day), but I have found the use of the date serial to be the best way.
Anyways, the DateAdd does the same, converting the date into a DateSerial first, and then does the math with the date serial. *******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.