# Finding exact date before specified months & weeks

**URL:** <https://www.ruby-forum.com/t/finding-exact-date-before-specified-months-weeks/183346>\
**Category:** Ruby\
**Created:** [February 12, 2010, 6:28am UTC](https://www.ruby-forum.com/t/finding-exact-date-before-specified-months-weeks/183346 "2010-02-12T06:28:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [February 12, 2010, 6:28am UTC](https://www.ruby-forum.com/t/finding-exact-date-before-specified-months-weeks/183346/1 "2010-02-12T06:28:10Z")

</div>

Dear All,

Iam using ruby1.8.6 and rails 2.2.2

I have small issue when using Date functionality. My need is to find  
date when months or weeks is given as input like,

When 3 months is given as input i need to calculate the exact date  
before 3 months. Also when 2 weeks is given as input i need to calculate  
the exact date before 2 weeks.

I have tried (Date.today - 3.months) but its not working could any one  
plz help me out.

Thanks in advance

Regards,  
Jose Martin

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [February 12, 2010, 6:46am UTC](https://www.ruby-forum.com/t/finding-exact-date-before-specified-months-weeks/183346/2 "2010-02-12T06:46:56Z")

</div>

On Feb 12, 2010, at 12:28 AM, dare ruby wrote:

> the exact date before 2 weeks.
> 
> I have tried (Date.today - 3.months) but its not working could any one  
> plz help me out.
> 
> Thanks in advance
> 
> ## Regards, Jose Martin
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I’m not sure that I understand exactly what you need, but perhaps this  
helps:

irb\> require ‘date’  
=\> true  
irb\> puts Date.today  
2010-02-12  
=\> nil  
irb\> puts(Date.today \<\< 3)  
2009-11-12  
=\> nil  
irb\> puts(Date.today - 14)  
2010-01-29  
=\> nil

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [February 12, 2010, 6:55am UTC](https://www.ruby-forum.com/t/finding-exact-date-before-specified-months-weeks/183346/3 "2010-02-12T06:55:31Z")

</div>

Thanks rob,

Exactly thats what i needed. It works fine in my application now. Thanks  
a lot Mr.Rob.

regards,  
Jose martin
