All,
I have used the following code to find the second Sunday of march.
lastdate_of_march = Date.new(current_year, 3, 31)
i = lastdate_of_march.wday
second_sunday = Date.new(current_year, 3, (31-i))
is there any simple method to find Second Sunday of March.
If any ! knows kindly help me..
Regards,
Rajaa
Comments
Re: To find 2nd Sunday of March
By Reid Thompson at 11/12/2010 - 22:04On 11/12/2010 1:22 AM, Rajaa Ramanathan wrote:
Re: To find 2nd Sunday of March
By Robert Klemme at 11/12/2010 - 05:17On Fri, Nov 12, 2010 at 7:22 AM, Rajaa Ramanathan
Come on, that's really not difficult. Start with the first day of
March and go from there. Knowing how many days there are in a week
should be sufficient. Note also, that you can use math operators on
Date instances (see "ri Date").
Cheers
robert
Re: To find 2nd Sunday of March
By Rob Biedenharn at 11/12/2010 - 10:43Think about it like this (assuming that you don't want to install the
chronic gem):
The second week is the 8th to the 14th of the month. Sunday is wday 0.
If the 14th is a Monday, which has a wday of 1, the second Sunday is
14-1=13th.
end_of_week_2 = Date.civil(Date.today.year, 3, 14)
second_sunday = end_of_week_2 - end_of_week_2.wday
Sunday is easiest with this method (because it is wday==0), but you
can generalize it to any day of the week.
-Rob
Rob Biedenharn
<a href="mailto: ... at AgileConsultingLLC dot com"> ... at AgileConsultingLLC dot com</a> <a href="http://AgileConsultingLLC.com/" title="http://AgileConsultingLLC.com/">http://AgileConsultingLLC.com/</a>
<a href="mailto: ... at GaslightSoftware dot com"> ... at GaslightSoftware dot com</a> <a href="http://GaslightSoftware.com/" title="http://GaslightSoftware.com/">http://GaslightSoftware.com/</a>