[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Calc Days from Date

relzne

10/11/2008 11:07:00 AM

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
4 Answers

Michael Guterl

10/11/2008 1:27:00 PM

0

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

relzne

10/11/2008 3:25:00 PM

0

On 11 Okt., 15:26, Michael Guterl <mgut...@gmail.com> wrote:
> On Sat, Oct 11, 2008 at 7:07 AM,  <rel...@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

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

Dejan Dimic

10/11/2008 4:29:00 PM

0

On Oct 11, 5:24 pm, rel...@bluewin.ch wrote:
> On 11 Okt., 15:26, Michael Guterl <mgut...@gmail.com> wrote:
>
>
>
> > On Sat, Oct 11, 2008 at 7:07 AM,  <rel...@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
>
> 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

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.

Todd Benson

10/11/2008 6:49:00 PM

0

On Sat, Oct 11, 2008 at 10:22 AM, <relzne@bluewin.ch> wrote:
> On 11 Okt., 15:26, Michael Guterl <mgut...@gmail.com> wrote:
>> On Sat, Oct 11, 2008 at 7:07 AM, <rel...@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
>
> 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?

Well, there's no Now method.