Hi Don -
Thank you.
So it's Linux, therefore I've been able to use Scrutinzer's solution with success:
echo $(date +CurrentWeek,%m/%d/%y)
echo $(date +CurrentWeekq,'"%m/%d/%y"')
echo $(date +CurrentPeriod,%^b%y)
echo $(date +CurrentPeriodq,'"%^b%y"')
echo $(date +1PeriodPrior,%^b%y)
echo $(date +1PeriodPriorq,'"%^b%y"' --date='1 month ago')
echo $(date +2PeriodPrior,%^b%y)
echo $(date +2PeriodPriorq,'"%^b%y"' --date='2 months ago')
echo $(date +CurrentPlanYear,"FY %Y")
echo $(date +CurrentPlanYearq,'"FY %Y"')
SO thank you both!
I do have a few more questions as to how to grab certain values.
Here are the additional variables:
CurrentQuarter,FY 2Q2017
CurrentQuarterq,"FY 2Q2017"
PriorQuarter,FY 1Q2017
PriorQuarterq,"FY 1Q2017"
PriorQuarterMnth1,JAN17
PriorQuarterMnth2,FAB17
PriorQuarterMnth3,MAR17
PriorQuarterMnth1q,"JAN17"
PriorQuarterMnth2q,"FEB17"
PriorQuarterMnth3q,"MAR17"
CurrentHalf,FY 1H2017
CurrentHalfq,"FY 1H2017"
I have the following code for the Current and Prior quarters, but I need help putting the output in the correct format (as shown above):
echo $(date +"%Y %m" | awk '{q=int($2/4)+1; printf("%sq%s\n", $1, q);}')
echo $(date +"%Y %m" | awk '{q=int($2/4);y=$1;if (q==0){q=4;y=y-1;}; printf("%sq%s\n", y, q);}')
As you can see, I also need help deriving PriorQuarter months 1-3.
Thank you for all your help!!
---------- Post updated 05-21-17 at 12:30 AM ---------- Previous update was 05-20-17 at 09:04 PM ----------
Hi -
Based on your suggestions, I've been able to acheeive my goal. However, I did need to use some if logic to get get there which helps with PriorQuarter Months 1-3 as well as prior year when in Quarter 1.
Please let me know if there is a better way, as I'm sure there is. Here is my code,
thanks!
_CH= Current Half
_PQ=Prior Quarter
_PQM1= Prior Quarter Month 1
echo ---------------------------------------------------------
echo "Advance Subvar Values"
echo ---------------------------------------------------------
if [ $(($(date +%m)/4+1)) -eq 1 ]
then
_CH=1
_PQ=4
_PQM1=OCT
_PQM2=NOV
_PQM3=DEC
_SVYEARL=$(date +%Y --date="1 year ago")
_SVYEARS=$(date +%y --date="1 year ago")
elif [ $(($(date +%m)/4+1)) -eq 2 ]
then
_CH=1
_PQM1=JAN
_PQM2=FEB
_PQM3=MAR
_SVYEARL=$(date +%Y)
_SVYEARS=$(date +%y)
elif [ $(($(date +%m)/4+1)) -eq 3 ]
then
_CH=2
_PQM1=APR
_PQM2=MAY
_PQM3=JUN
_SVYEARL=$(date +%Y)
_SVYEARS=$(date +%y)
elif [ $(($(date +%m)/4+1)) -eq 4 ]
then
_CH=2
_PQM1=JUL
_PQM2=AUG
_PQM3=SEP
_SVYEARL=$(date +%Y)
_SVYEARS=$(date +%y)
else
_PQ=$(($(($(date +%m)/4+1))-1))
fi
#::-- Read file contents into variables and pass to MaxL --::#
echo $(date +CurrentWeek,%m/%d/%y)
echo $(date +CurrentWeekq,'"%m/%d/%y"')
echo $(date +CurrentPeriod,%^b%y)
echo $(date +CurrentPeriodq,'"%^b%y"')
echo $(date +1PeriodPrior,%^b%y)
echo $(date +1PeriodPriorq,'"%^b%y"' --date='1 month ago')
echo $(date +2PeriodPrior,%^b%y)
echo $(date +2PeriodPriorq,'"%^b%y"' --date='2 months ago')
echo $(date +CurrentQuarter,"FY $(expr $(expr $(date -d '-1 month' +%m) - 1) / 3 + 1)Q%Y")
echo $(date +CurrentQuarterq,'"'"FY $(expr $(expr $(date -d '-1 month' +%m) - 1) / 3 + 1)Q%Y"'"')
echo $(date +CurrentHalfq,'"'"FY ${_CH}H%Y"'"')
echo $(date +CurrentPlanYear,"FY %Y")
echo $(date +CurrentPlanYearq,'"FY %Y"')
echo $(date +CurrentYear,"FY %Y")
echo $(date +CurrentYearq,'"FY %Y"')
echo $(date +PriorQuarterAD,AD${_PQ}-${_SVYEARS})
echo $(date +PriorQuarterADq,'"'"AD${_PQ}-${_SVYEARS}"'"')
echo $(date +PriorQuarterMnth1,"${_PQM1}${_SVYEARS}")
echo $(date +PriorQuarterMnth2,"${_PQM2}${_SVYEARS}")
echo $(date +PriorQuarterMnth3,"${_PQM3}${_SVYEARS}")
echo $(date +PriorQuarterMnth1q,'"'"${_PQM1}${_SVYEARS}"'"')
echo $(date +PriorQuarterMnth2q,'"'"${_PQM2}${_SVYEARS}"'"')
echo $(date +PriorQuarterMnth3q,'"'"${_PQM3}${_SVYEARS}"'"')
echo $(date +PriorQuarter,"FY ${_PQ}Q${_SVYEARL}")
echo $(date +PriorQuarterq,'"'"FY ${_PQ}Q${_SVYEARL}"'"')
echo $(date +CurrentQtrInput,"FY $(expr $(expr $(date -d '-1 month' +%m) - 1) / 3 + 1)Q%Y_input")
echo $(date +CurrentQtrInputq,'"'"FY $(expr $(expr $(date -d '-1 month' +%m) - 1) / 3 + 1)Q%Y_input"'"')
echo $(date +PriorQtrInput,"FY ${_PQ}Q${_SVYEARL}_input")
echo $(date +ALLC_CurrentWeek,%m/%d/%y)
echo $(date +ALLC_CurrentWeekq,'"%m/%d/%y"')
echo $(date +ALLC_CurrentPeriod,%^b%y)
echo $(date +ALLC_CurrentPeriodq,'"%^b%y"')