I am writing a shell script, and need to calculate the first and last days of a quarter from the current date. This is for use in Ingres 10 SQL statements triggered from within the script. The Ingres runs on a Solaris server with ksh.
So, if today is 31/01/17, I would want to calculate the following
- the first date of the current quarter (01/01/17)
- the last date of the current quarter (31/03/17). It would be OK here to return an exclusive to date if necessary (i.e. 01/04/17)
- the first date of the previous quarter (01/10/16)
- the last date of the previous quarter (31/12/16). An exclusive-to result of 01/01/17 would also be OK.
Can anyone please help? I've seen questions related to getting the quarter number but that's not really helping.
I've tried the following but its not working as the variables are not being populated in the case statement
CURR_MONTH=`date +%m`
echo "Current month num = $CURR_MONTH"
CURR_YEAR=`date +%Y`
echo "Current year = $CURR_YEAR"
let "LAST_YEAR = $CURR_YEAR - 1"
echo "Last year = $LAST_YEAR"
case $CURR_MONTH in
05) CURR_Q_FROM = 01.04.${CURR_YEAR}
CURR_Q_TO = "30.06.${CURR_YEAR}"
PREV_Q_FROM = "01.01.${CURR_YEAR}"
PREV_Q_TO = "31.03.${CURR_YEAR}" ;;
esac
echo "Current Q From = $CURR_Q_FROM"
echo "Current Q To = $CURR_Q_TO"
echo "Prev Q From = $PREV_Q_FROM"
echo "Prev Q To = $PREV_Q_TO"
I get the following output
Current month num = 05
Current year = 2017
Last year = 2016
Month to be extracted = April 2017
./stats_report_monthly.sh[85]: CURR_Q_FROM: not found
./stats_report_monthly.sh[86]: CURR_Q_TO: not found
./stats_report_monthly.sh[87]: PREV_Q_FROM: not found
./stats_report_monthly.sh[88]: PREV_Q_TO: not found
Current Q From =
Current Q To =
Prev Q From =
Prev Q To =