irb(main):001:0> require 'date'
=> true
irb(main):002:0> puts "February 2nd 2007 and January 25th 2007 are
#{Date.new(2007, 2, 3) - Date.new(2007, 1, 25)} days apart"
February 2nd 2007 and January 25th 2007 are 9 days apart
=> nil
irb(main):003:0>
If you subtract a date object from a date object, the result is "how many
days later the current date is than x."
HTH,
Felix
···
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Michael Linfield
Sent: Saturday, September 01, 2007 4:57 PM
To: ruby-talk ML
Subject: calendar events
i want a simply get the amount of days inbetween a range of dates. IE:
1/25 - 2/3 is 8 days difference.
My initial approach the the problem was to create a huge
variable setup:
jan = 31 #31 = days in january
feb = 28
mar = 31
apr = 30
im sure thers a better and cleaner way, any ideas on how to approach
this?
just another quick question...if i wanted to put a string into a date
format such as the following:
res = []
array = ["2/14/2005",83,35,23]
res << array.grep(/2/\14/\2005/)
# so now res has "2/14/2005" in it...how would i turn that into a --
specdate = Date.new(2, 24, 2005)
so i need 2/14/2005 turned into a date object, preferably not having to
use the format of Date.new(year,day,month) ...id prefer to have it in
the format of month,day,year if possible
Once you have a string containing the date separated by slashes, you can
split the string on separators to parse the date parts into variables, and
then use those to construct the date object.
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Michael Linfield
Sent: Saturday, September 01, 2007 6:35 PM
To: ruby-talk ML
Subject: Re: calendar events
just another quick question...if i wanted to put a string into a date
format such as the following:
res =
array = ["2/14/2005",83,35,23]
res << array.grep(/2/\14/\2005/)
# so now res has "2/14/2005" in it...how would i turn that into a --
specdate = Date.new(2, 24, 2005)
so i need 2/14/2005 turned into a date object, preferably not
having to
use the format of Date.new(year,day,month) ...id prefer to have it in
the format of month,day,year if possible
# res = []
# array = ["2/14/2005",83,35,23]
# res << array.grep(/2/\14/\2005/)
# so now res has "2/14/2005" in it...how would i turn that into a --
# specdate = Date.new(2, 24, 2005)
# so i need 2/14/2005 turned into a date object, preferably not
# having to use the format of Date.new(year,day,month)
# ...id prefer to have it in
# the format of month,day,year if possible
hmmm, you already have that copy in array. why not put a date object right into res. one you have the date obj, you can format it anyway you like
On Sep 1, 2007, at 9:55 PM, "Felix Windt" <fwmailinglists@gmail.com> wrote:
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Michael Linfield
Sent: Saturday, September 01, 2007 6:35 PM
To: ruby-talk ML
Subject: Re: calendar events
just another quick question...if i wanted to put a string into a date
format such as the following:
res =
array = ["2/14/2005",83,35,23]
res << array.grep(/2/\14/\2005/)
# so now res has "2/14/2005" in it...how would i turn that into a --
specdate = Date.new(2, 24, 2005)
so i need 2/14/2005 turned into a date object, preferably not
having to
use the format of Date.new(year,day,month) ...id prefer to have it in
the format of month,day,year if possible
Once you have a string containing the date separated by slashes, you can
split the string on separators to parse the date parts into variables, and
then use those to construct the date object.
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Michael Linfield
Sent: Saturday, September 01, 2007 6:35 PM
To: ruby-talk ML
Subject: Re: calendar events
just another quick question...if i wanted to put a string into a date
format such as the following:
res =
array = ["2/14/2005",83,35,23]
res << array.grep(/2/\14/\2005/)
# so now res has "2/14/2005" in it...how would i turn that into a --
specdate = Date.new(2, 24, 2005)
so i need 2/14/2005 turned into a date object, preferably not
having to
use the format of Date.new(year,day,month) ...id prefer to have it in
the format of month,day,year if possible
Once you have a string containing the date separated by slashes, you can
split the string on separators to parse the date parts into variables, and
then use those to construct the date object.