If I have a weeknumber and a year, is there an easy way to get the
dates that fall in this weeknumber or the first day of that week (the
other I can calculate).
regards
If I have a weeknumber and a year, is there an easy way to get the
dates that fall in this weeknumber or the first day of that week (the
other I can calculate).
regards
Found it myself
Date.neww(2007,5,6)
Input year, week and daynumber all in the commercial calendar and you
get a date back.
On Mar 26, 1:49 pm, “bitterbal” [email protected] wrote:
If I have a weeknumber and a year, is there an easy way to get the
dates that fall in this weeknumber or the first day of that week (the
other I can calculate).
require ‘date’
def sunday_before( d )
d - d.wday
end
def start_of_week( week_number, year )
sunday_before( Date.new( year, 1, 1 ) ) + (week_number * 7)
end
puts start_of_week( 0, 2007 )
puts start_of_week( 1, 2007 )
puts start_of_week( 51, 2007 )
puts start_of_week( 52, 2007 )
puts start_of_week( 53, 2007 )
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs