Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparision of date in ruby

how to compare particular date with today to know whether that paricular date is greater than today

Thanks Harish.

like image 801
harish Avatar asked Jul 21 '10 05:07

harish


2 Answers

@date = "2010-07-20".to_date # 20th July
@today=Date.today # 21st July

if @date >= @today
  puts "@date is greater than or equal to today's date"
else
  puts "@date is less than today's date"  
end

O/P

@date is less than today's date
like image 69
Salil Avatar answered Sep 25 '22 10:09

Salil


date object has future? and past? methods. It's the best way I can think of.

like image 33
samuil Avatar answered Sep 22 '22 10:09

samuil