0

We use to run shell scripts through Control-M and shells script accepts execution date as input parameter and script should calculate last month's last day whatever order date we run. I am trying to get the same as below but not able to. Please help.

run_date=20210615 startMM_run_date=`date --date="$run_date" '%Y%m01'` --> 20210601 

Here how to get "2021/05/31" from $startMM_run_date. Please advice.

0

1 Answer 1

2

Assuming GNU date

run_date=20210615 # extract the year and month, and set the day as 01, then subtract 1 day endOfLastMonth=$(date -d "${run_date:0:4}-${run_date:4:2}-01 - 1 day" "+%Y-%m-%d") 
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.