Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if DateTime value is today, tomorrow or later

I have an object attribute of the DateTime class.

How would I understand if the saved date is today, tomorrow or else later?

like image 980
Fellow Stranger Avatar asked Oct 26 '14 22:10

Fellow Stranger


1 Answers

Here are some useful ways to achieve it:

datetime = DateTime.now  => Sun, 26 Oct 2014 21:00:00  datetime.today? # => true datetime.to_date.past? # => false (only based on date) datetime.to_date.future? # => false  (only based on date)  datetime.to_date == Date.tomorrow # => false datetime.to_date == Date.yesterday # => false 
like image 174
Alireza Avatar answered Oct 06 '22 00:10

Alireza