I'm interested in outputting a representation of the current year-quarter, as well as the year-quarter for the previous month.
If today is 2012 January 1st, I'd like to get
2012q1
and
2011q4
as the respective outputs.
|
I'm interested in outputting a representation of the current year-quarter, as well as the year-quarter for the previous month. If today is 2012 January 1st, I'd like to get
and
as the respective outputs. |
|||
|
|
|
Probably, there is no direct solution. You could use
A
|
|||
|
|
Split the format with date, calculate with awk, format with printf:
Just date and bash:
|
|||||
|
|
|
Call
|
|||
|
|
|
One (kinda ugly) solution, using BASH arithmetic evaluation and the GNU
|
|||||||||||||
|
|
An alternative, more as a curiosity. If GNU
|
||||
|
|
|
Basic math for this quarter and last month's quarter:
|
|||
|
|
|
Use my dateutils:
The |
|||
|
|
|
All solutions that divide by four fail, for instance November:
The correct math would be:
And as such, the quarter of current and previous month would be:
It's only twelve values to check, really…
|
||||
|
|