Counting the Days Since an Arbitrary Date : Date Calculation « Date « Ruby






Counting the Days Since an Arbitrary Date



require 'date'
def last_modified(file)
  t1 = File.stat(file).ctime
  t2 = Time.now
  elapsed = (t2-t1)/(60*60*24)
  puts "#{file} was last modified #{elapsed} days ago."
end

last_modified("c:\\")

 








Related examples in the same category

1.Subtract 61 days from a date:
2.Add and subtract six months using the >> and << methods.
3.Doing Date Arithmetic
4.Doing DateTime Arithmetic
5.Minus one DateTime from another
6.Move DateTime
7.leap year day
8.advent calendar
9.Minus DateTime by day
10.Remaining days