
require 'date'
# Today
Date.today
# 1st of this month
Date.new(Time.now.year, Time.now.month, 1)
# 1st of next month
Date.new(Time.now.year, Time.now.month, 1) >> 1
# 1st of last month
Date.new(Time.now.year, Time.now.month, 1) << 1
# 1 week later
Date.today + 7
# 1 week before
Date.today - 7
And you can use these Date valuables in Model 'where' phrase on Rails.

models = SomeModel.where("date <= ?", Date.today)
No comments :
Post a Comment