Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Months ago in ruby

Tags:

class

ruby

I can't figure out a way (using class definitions) to get months ago. Seconds, days, and minutes are all fine because they're always constants. However since months isn't always constant, i need to know a way for ruby to know how many days are in the current month.

like image 404
Eli Avatar asked Oct 04 '10 15:10

Eli


1 Answers

If your application uses ActiveSupport (e.g. a Rails application), you can use

3.months.ago

to get the current date less 3 months.

like image 77
Simone Carletti Avatar answered Oct 10 '22 02:10

Simone Carletti