# Calc Days from Date

**URL:** <https://www.ruby-forum.com/t/calc-days-from-date/150683>\
**Category:** Ruby\
**Created:** [October 11, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683 "2008-10-11T13:12:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683/1 "2008-10-11T13:12:07Z")

</div>

Hello.  
I am Ruby Beginner. Now I am trying to write a code, that calcs days  
between two dates.

I ask the user for a date. Then the User type a german Date (for  
example 12.06.2006). This is working well. Now, what does I have to do  
to calc the days between now and the date which has the user give in?

Thanks for your help.

Fridrich

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683/2 "2008-10-11T15:29:41Z")

</div>

On Sat, Oct 11, 2008 at 7:07 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello.  
> I am Ruby Beginner. Now I am trying to write a code, that calcs days  
> between two dates.
> 
> I ask the user for a date. Then the User type a german Date (for  
> example 12.06.2006). This is working well. Now, what does I have to do  
> to calc the days between now and the date which has the user give in?
> 
> Thanks for your help.

tday = Date.today  
bday = Date.new(2009, 4, 30)

days = (bday - tday).to\_i =\> 201

HTH,  
Michael G.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683/3 "2008-10-11T17:25:40Z")

</div>

On 11 Okt., 15:26, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> tday = Date.today  
> bday = Date.new(2009, 4, 30)
> 
> days = (bday - tday).to\_i =\> 201
> 
> HTH,  
> Michael G.

Hi Michael

Thank you for your help. I have now done it with the fallowing code:

datum = Date.Parse(datums)  
seconds = Time.Now-datum

This is also working. The variable datums holds a date which is the  
user give in over the console. Could there be a problem with my code?

Fridrich

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683/4 "2008-10-11T20:52:21Z")

</div>

On Sat, Oct 11, 2008 at 10:22 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Thanks for your help.
> 
> Thank you for your help. I have now done it with the fallowing code:
> 
> datum = Date.Parse(datums)  
> seconds = Time.Now-datum
> 
> This is also working. The variable datums holds a date which is the  
> user give in over the console. Could there be a problem with my code?

Well, there’s no Now method.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/calc-days-from-date/150683/5 "2008-10-11T18:30:41Z")

</div>

On Oct 11, 5:24 pm, removed\_email\_address@domain.invalid wrote:

> > > example 12.06.2006). This is working well. Now, what does I have to do  
> > > Michael G.
> 
> Fridrich

There are so many ways people writes a date so it is to be expected to  
have problem if you aloud free form input.  
If datums have a time component the things become even more  
interesting.  
Parsing the user input is always a tricky business.
