I have a date and i want to find out the months of that particular quarter.How can i have this done in ruby in the easiest possible way? I mean if the date i give is 27-04-2011
, then the result i must get is April, May,June as string or int like 4,5,6 for April to June.
You can get the quarter from any date by doing this:
quarter = (((Date.today.month - 1) / 3) + 1).to_i
Or even shorter:
quarter = (Date.today.month / 3.0).ceil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With