current date, calculate one moth back intit and end date

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

current date, calculate one moth back intit and end date

Post by sal21 »

I need to a function to calculte the first and last date of one month back based current date...example:

now is 13/10/2010

calculate the first day and the last day of one month back, in this case is september.

first_day =01/09/2010
last_day=30/09/2010

note:
in vb6 classic
tks.

User avatar
mbarron
2StarLounger
Posts: 112
Joined: 25 Jan 2010, 20:19

Re: current date, calculate one moth back intit and end date

Post by mbarron »

First day of previous month:
DateSerial(Year(Date), Month(Date) - 1, 1)

Last day of previous month:
Date - Day(Date)

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: current date, calculate one moth back intit and end date

Post by HansV »

Let's say that your date is stored in a variable MyDate.

The first of the previous month is DateSerial(Year(MyDate), Month(MyDate) - 1, 1)
The last of the previous month is DateSerial(Year(MyDate), Month(MyDate), 0)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: current date, calculate one moth back intit and end date

Post by sal21 »

HansV wrote:Let's say that your date is stored in a variable MyDate.

The first of the previous month is DateSerial(Year(MyDate), Month(MyDate) - 1, 1)
The last of the previous month is DateSerial(Year(MyDate), Month(MyDate), 0)
tks for sugestion! :cheers: :thankyou:

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: current date, calculate one moth back intit and end date

Post by sal21 »

mbarron wrote:First day of previous month:
DateSerial(Year(Date), Month(Date) - 1, 1)

Last day of previous month:
Date - Day(Date)
Tks! :thankyou: