Forum: Ruby Calc Days from Date

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
67067a7c213c8a9e81db2f3e14307ef3?d=identicon&s=25 unknown (Guest)
on 2008-10-11 13:12
(Received via mailing list)
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
D337e2cf7c6d03caac6988d83e0e7f66?d=identicon&s=25 Michael Guterl (Guest)
on 2008-10-11 15:29
(Received via mailing list)
On Sat, Oct 11, 2008 at 7:07 AM,  <relzne@bluewin.ch> 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 Guterl
67067a7c213c8a9e81db2f3e14307ef3?d=identicon&s=25 unknown (Guest)
on 2008-10-11 17:25
(Received via mailing list)
On 11 Okt., 15:26, Michael Guterl <mgut...@gmail.com> wrote:
>
> tday = Date.today
> bday = Date.new(2009, 4, 30)
>
> days = (bday - tday).to_i         => 201
>
> HTH,
> Michael Guterl

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
04952a6ee948f345e9c3727850d09a1b?d=identicon&s=25 Dejan Dimic (Guest)
on 2008-10-11 18:30
(Received via mailing list)
On Oct 11, 5:24 pm, rel...@bluewin.ch wrote:
> > > example 12.06.2006). This is working well. Now, what does I have to do
> > Michael Guterl
>
> 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.
289cf19aa581c445915c072bf45c5e25?d=identicon&s=25 Todd Benson (Guest)
on 2008-10-11 20:52
(Received via mailing list)
On Sat, Oct 11, 2008 at 10:22 AM,  <relzne@bluewin.ch> 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.
This topic is locked and can not be replied to.