Q:

How to subtract date and time out of date time object?

Here is what I am trying to achieve - I have set up a scheduler to execute midnight of every friday, which collects the data from a service for the start date of last friday at 00:00:00 hrs and end time of last thursday at 23:59:59 hrs. Since it has to work every friday, I cannot hard code the dates so I thought of trying out DateTime.
So as per my requirement, if I am running the job on this Friday midnight i.e at "2014-12-12T03:00:00Z", then my start date should be "2014-12-05T00:00:00Z" and my end date should be "2014-12-11T23:59:59Z".
So to get start and end dates, I am trying to subtract days out of my now object. This is what I tried:
    now = DateTime.now
    p now.new_offset(0).to_s

    startDate = now - 7
    p startDate.new_offset(0).to_s

    endDate = now - 1
    p endDate.new_offset(0).to_s

This gives me the right date, but the time is wrong i.e. instead of start date with 00:00:00 and end date with 23:59:59 this would be start date with 03:00:00 and end date with 03:00:00. 
How do I modify the DateTime object to get the start date with time at beginning of the day and end date with time at end of the day? 
Sorry I am very bad in dealing with dates. Thanks in advance!!

A:

You can use he beginning_of_day and end_of_day methods
1.9.3-p448 :001 > DateTime.now.beginning_of_day
 => Tue, 09 Dec 2014 00:00:00 +0300
1.9.3-p448 :002 > DateTime.now.end_of_day
 => Tue, 09 Dec 2014 23:59:59 +0300

