Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if date is over a day old, over a year old etc?

What would the best way be to check if a date is more than a day old, or a year old etc?

like image 761
Mo. Avatar asked May 28 '11 00:05

Mo.


People also ask

How to check if a date is older than the current date?

First minus the current date and then uses isBefore () to check if a date is a certain period older than the current date. 1.1 This example checks if a date is 6 months older than the current date.

How to select a date that is over one year old?

In the Select Specific Cells dialog, check Cell option, and choose Less than in the first drop down list and click to select the date which is over one year old from today in the beside textbox.

How long does a check last (and why)?

Most of the banks in the United States accept checks which is up to six months from the date written at the date column on the check, even though there are separate check expiry time period for States and local governments. After his date, checks can be considered as stale checks or invalid checks as it will not be accepted by any of the banks.

Can you deposit a check that is 3 years old?

If this check were in a business deposit, more often than n Can you deposit a check that is 3 years old? Most of the banks in the United States accept checks which is up to six months from the date written at the date column on the check, even though there are separate check expiry time period for States and local governments.


2 Answers

See this question: comparision of date in ruby The compare to a value like

1.day.ago
1.month.ago
1.year.ago

Using these produces the following output:

Loading development environment (Rails 3.0.7)
ruby-1.9.2-p180 :001 > 1.year.ago
 => Thu, 27 May 2010 17:45:25 UTC +00:00 
ruby-1.9.2-p180 :002 > 1.month.ago
 => Wed, 27 Apr 2011 17:45:32 UTC +00:00 
ruby-1.9.2-p180 :003 > 1.day.ago
 => Thu, 26 May 2011 17:45:36 UTC +00:00 
ruby-1.9.2-p180 :004 > 

and see if that works.

like image 125
Devin M Avatar answered Nov 07 '22 06:11

Devin M


Use ActiveSupport helpers

@date < 1.day.ago

@some_other_date < 2.years.ago
like image 29
edgerunner Avatar answered Nov 07 '22 08:11

edgerunner