1

In Python, if I want to check for a specific date + 24 hours has passed, I will write:

from datetime import datetime, timedelta

some_date = datetime(2013, 1, 10, 11, 0)
day = timedelta(1)

# Checks if some_date + 1 day is before today's date
print some_date + day < datetime.now()

How can I construct a time difference of 1 day and checks if a specific date + 1 day is before today's date in Ruby?

Thierry Lam
  • 45,304
  • 42
  • 117
  • 144

1 Answers1

2
require 'time'

xmas = DateTime.new(2013, 12, 25)
puts x = xmas + 1 # 2013-12-26T00:00:00+00:00
d = DateTime.now
puts x > d        # true
puts x - d        # 30167183979194791/86400000000000 (a Rational)
puts d >> 12      # 2014-01-10T21:15:20+01:00
steenslag
  • 79,051
  • 16
  • 138
  • 171