Not able to fetch previous month first date and last date

I am not able to fetch first date and last date previous month

date -d -1month +%Y-%m-%d 
date -d -1month +%Y-%m-%d

I need two format dd-mm-yyy
previous month 01-03-2016
previous month 31-03-2016
and also only date 1 to 31

Aprriciate your replay

While it's not that difficult to get at the last day of the last month:

date -d$(date +-%d)days
Do 31. M�r 13:50:08 CEST 2016

, calculating its first day is a bit more cumbersome. How about finding the solution in the FAQ area, e.g. Simple date and time calulation in BASH or Finding the nth Particular Week in a Month � shell script

Or this one

HI Rudic,
It is diplsy correct output.please let me know if any other way to fetch for the same

 
set `date +%m" "%Y`
CURMTH=$1
CURYR=$2
if [ $CURMTH -eq 1 ]
then PRVMTH=12
     PRVYR=`expr $CURYR - 1`
 else PRVMTH=`expr $CURMTH - 1`
      PRVYR=$CURYR
 fi
if [ $PRVMTH -lt 10 ]
 then PRVMTH="0"$PRVMTH
fi
LASTDY=`cal $PRVMTH $PRVYR | egrep "28|29|30|31" |tail -1 |awk '{print $NF}'`
echo First Day: 01-$PRVMTH-$PRVYR
echo Last Day: $LASTDY-$PRVMTH-$PRVYR
 

Output-01-03-2016
31-03-2016

Hi.

See date - First and last day of a month - Unix & Linux Stack Exchange for both simple and complex solutions with shell commands, some with GNU date, one without GNU date.

Best wishes ... cheers, drl