<p>I have a Ruby DateTime which gets filled from a form. Additionally I have n hours from the form as well. I'd like to subtract those n hours from the previous DateTime. (To get a time range).</p>

<p>DateTime has two methods "-" and "&lt;&lt;" to subtract day and month, but not hour. (<a href="https://ruby-doc.org/stdlib-2.5.1/libdoc/date/rdoc/DateTime.html" rel="noreferrer">API</a>). Any suggestions how I can do that?</p>

If you are working in
Rails
, the following super-intutive possibility exists:
```
```
> Time.now - 12.hours
=> 2019-08-19 05:50:43 +0200
```
```
(This also works with
seconds
,
minutes
,
days
, and
years
)
if you're using just Ruby,
```
DateTime
```
can't do this, but
```
Time
```
can:
```
```
t = Time.now
t = t - (hours*60**2)
```
```
Note that
```
Time
```
also stores date information, it's all a little strange.
If you have to work with
```
DateTime
```
```
```
DateTime.commercial(date.year,date.month,date.day,date.hour-x,date.minute,date.second)
```
```
might work, but is ugly. The doc says
```
DateTime
```
is immutable, so I'm not even sure about
```
-
```
and
```
<<
```