Rails – Get the current week’s and month’s start and end dates

Instead of using Time.now

Use the following code to get your queries solved

d = Date.today

d.at_beginning_of_week
#Mon, 13 Aug 2012
d.at_beginning_of_week.strftime
#"2012-08-13"
d.at_beginning_of_week.strftime("%d")
#"13" -> To print the date.

Similarly you can find multiple methods in the Date Class

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)