Riding The Breeze
Jump to content
last_day_of_the_month = (Date.parse(year_to_process + "-" + (month_to_process.to_i + 1).to_s + "-01") - 1).mday().to_s rescue "31"
The final rescue is due to catch the error when month_to_process is 12.
Feb 08, 2007 by simone Trackback Filed in: Computer, Ruby Comment feed
Won't (month + 1) returns 13 when december!!!!!????????
You are right. Just changed the function to works for December too.
Or do this…
Date.parse( "#{year}-#{ (month + 1) % 12 }-01" ) - 1
Martin: does not work if month = 11… (11+1)%12 = 0…
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Template designed by praegnanz.de.
# Philippe Rathe on August 31st, 2009
Won't (month + 1) returns 13 when december!!!!!????????
# hpatoio on September 1st, 2009
You are right. Just changed the function to works for December too.
# Martin Streicher on January 19th, 2010
Or do this…
Date.parse( "#{year}-#{ (month + 1) % 12 }-01" ) - 1
# alain on February 9th, 2010
Martin: does not work if month = 11…
(11+1)%12 = 0…