First Day Of Previous Month

T

The Report Guy

Hi,

I'm trying to capture the day first day of the previous month. I figured
out how to do it for the current month (see function below) but I can't
figure out how to make my function go back to the previous month.

Date()-Day(Date())+1

Thanks
 
J

Jon Lewis

Sure there must be an easier way but this works:
Date()- Day(Date()) - Day(Date()- Day(Date())-1)
 
K

Ken Sheridan

There are various ways, e.g.

DateSerial(Year(Date()),Month(Date())-1,1)

Even if the current month is January, and Month(Date())-1 consequently
evaluates to 0, this will nevertheless return 1 December of the previous year.

Ken Sheridan
Stafford, England
 
T

Tom

I use the following for the first day of the month of any given date
(add error handlers as appropriate):


****************
Public Function fncFirstofMonth(dtmDate As Date) As Date

fncFirstofMonth = DateSerial(Year(dtmDate), Month(dtmDate), 1)

End Function
******************

Easily modified to:

*****************
Public Function fncFirstofLastMonth(dtmDate As Date) As Date

fncFirstofLastMonth = dateadd("m", -1, DateSerial(Year(dtmDate),
Month(dtmDate), 1))

End Function
******************

Tom
 
T

The Report Guy

Ken & Jon thank you both. I played with both functions and they both work
great. I will add the functions on my query so I can finally automate our
reports.
 

Ask a Question

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.

Ask a Question

Top