Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help... Dates!!!!!! 1

Status
Not open for further replies.

andrest

Programmer
Jul 25, 2002
20
CA
Does anybody now how to get the first day and last day of a month?
 
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 )

Matt
 
SORRY...

CCLINTS original post was correct, mine was wrong!
Code:
= Day(DateSerial(Year(TheDate), Month(TheDate) + 1, 0))
is correct...

That'll teach me for being so clever to post without checking won't it!!

I guess thats worth a star, by way of apology

Matt
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top