I am new to ruby on rails and got stuck in dates. I used Time.now to get the current time. Now I want to find out the srart and end dates for the current week and current month. For instance:
If Time.now returns me –
2012-08-13 15:25:35 +0530
Then the start and end dates for the current week are:
2012-08-12 - 2012-08-18
Then the start and end dates for the current month are:
2012--08-01 - 2012-08-31
I am implementing the same using the code:
Time.now.wday
=> 1
Time.now - 1.day
=> 2012-08-12 15:31:44 +0530
Time.now + 5.day
=> 2012-08-19 15:32:38 +0530
and so on.. But I dont find it a convenient way to do this. Iam sure Ruby on Rails does hold a better solution. Can anyone suggest to figure out the same..
Instead of using Time.now
Use the following code to get your queries solved
Similarly you can find multiple methods in the Date Class