DateTime Range : Date Range « Range « Ruby






DateTime Range


require 'date'
sunday = DateTime.new(2006, 1, 1)

(sunday...sunday+7).each do |d|
  puts "#{d.strftime("%a")} #{d.wday} #{d.cwday}"
end
# Sun 0 7
# Mon 1 1
# Tue 2 2
# Wed 3 3
# Thu 4 4
# Fri 5 5
# Sat 6 6

 








Related examples in the same category

1.Iterating Over Dates
2.Range based on DateTime
3.Range based on Time