Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to judge whether a time/date is today, in ruby?

I have a settlement, I want to judge if the return_service_date is today, how to do this?

This is my code (rails):

if settlement.return_service_date && 
   settlement.return_service_date.to_s(:date) == Time.now.to_s(:date)

Is there a better way to do this?

like image 219
qichunren Avatar asked Feb 25 '10 08:02

qichunren


1 Answers

In Rails, you can do:

settlement.return_service_date.today?
like image 91
molf Avatar answered Nov 15 '22 22:11

molf