cancel
Showing results for 
Search instead for 
Did you mean: 

How to get start date of the last month and end date of the last month

Former Member
0 Kudos

Hi

On the given  date, How to find the start date of previous month  and end date of the previous month of  the given date.

For Example I have given the date 20-12-2014 as input , then   I have to get previous month start date as '01-11-2013' and end of the previous month '30-11-2013'  , Please anybody can help me with proper logic to get the solution.

Regards

Pol

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Polachan;

  I would recommend having a look at the DaysAfter ( ) and RelativeDate ( )  PB methods to help you in this endevour.

Regards ... Chris

Answers (3)

Answers (3)

Former Member
0 Kudos

Here's a shorter one:

date ld,ld_first,ld_last

em_date.getdata(ld)

ld_last = relativedate(ld,-day(ld))

ld_first = date(year(ld_last),month(ld_last),1)

messagebox(string(ld),string(ld_first)+', '+string(ld_last))

Former Member
0 Kudos

Please try as follow,

Date   ldt_in_date

Long   ll_y , ll_m

// Input date.. I use Today() as input date..
ldt_in_date = Today()

ll_y  = Year (ldt_in_date)
ll_m  = Month(ldt_in_date)

IF ll_m = 1 THEN
ll_m = 12
ll_y --
ELSE
ll_m --
END IF

MessageBox( "Last Month Start date" , String( Date(ll_y, ll_m, 1) ) )
MessageBox("Last Month End date" , String( RelativeDate(Date(Year(ldt_in_date), Month(ldt_in_date), 1), -1)))

Regards,

Jahir

Former Member
0 Kudos

The easiest way to get the last day of a month is to do a RelativeDate passing the first of the following month as the date and -1 as the number of days.