I am getting a date from environment variable and want to do some processing by subtracting 2 months from the date passed through the environment variable.
Thanks for the reply. I have tried the below code, it's working fine for most of the dates but with few discrepancies.
date_var=$1
day_var=${date_var##*-}
date_2m_ago=$(date -d "$date_var -2 months" +%Y-%m-%d)
day_2m_ago=${date_2m_ago##*-}
if [[ ${day_var} = ${day_2m_ago} ]]
then
echo "same"
else
echo "difference"
date_2m_ago=$(date -d "date_2m_ago -1 days" +%Y-%m-%d)
echo $date_2m_ago
fi
The date passed as input parameter will always be the end of the month date and I need the output to be 2 months prior to the input date but want the O/P to be the end of the month date.
The above code is giving me the following output :