Read more

Calendar quarter calculations in Ruby and MySQL

Henning Koch
June 20, 2012Software engineer at makandra GmbH

ActiveSupport >= 3 has

Date.parse('2011-02-10').beginning_of_quarter #=> 2011-01-01
Date.parse('2011-02-10').end_of_quarter #=> 2011-03-31
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

You can manually calculate the quarter index like

(Date.parse('2011-02-10').month / 3.0).ceil #=> 1

Yes, you do actually divide by 3.0, not 4.0.

MySQL has

SELECT QUARTER('2011-02-10'); #=> 1
Posted by Henning Koch to makandra dev (2012-06-20 10:54)