ruby - How to find the dates which are there in a week or month till date -


how find dates there in week or month till date.

days_for_week should return 19,20,21 (assuming current date 21st) days_for_month should return 1..21 (assuming current date 21st) 

active support provides lot of useful methods at_beginning_of_week, at_end_of_week, at_beginning_of_month etc ..

> date.today.at_beginning_of_week => mon, 20 may 2013 

for particular case, do

> (date.today.at_beginning_of_week..date.today).map &:day => [20, 21] 

similarly

> (date.today.at_beginning_of_month..date.today).map &:day => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] 

or simply

> 1..date.today.day 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -