DateTime problem

DateArray = [“Apr”, “2”, “2007”]

How can i read the month and year in the array???

The OUTPUT:
day = 01
month = 04
year = 07

teach-a-man-to-fish answer: check RDoc Documentation , under
Date

quick answer:
d = Date.civil(2007,4,2)
puts “OUTPUT:\n day = #{d.day}\n month=#{d.month}\n year=#{d.year}”

also try out puts d.strftime(“%m %d %Y”)

----- Original Message -----
From: “Cool W.” [email protected]
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” [email protected]
Sent: Tuesday, June 26, 2007 8:50 PM
Subject: DateTime problem

On Jun 26, 2007, at 8:50 PM, Cool W. wrote:

DateArray = [“Apr”, “2”, “2007”]

How can i read the month and year in the array???

The OUTPUT:
day = 01
month = 04
year = 07

Something like this?

require "ParseDate" DA = ["Apr", "2", "2007"] args = ParseDate.parsedate("#{DA[1]} #{DA[0]} #{DA[2]}") date = Time.local(*args).strftime(<<FMT) \tday = %d \tmonth = %m \tyear = %y FMT puts date day = 02 month = 04 year = 07

Regards, Morton

Morton G. wrote:

FMT

Same idea, but slightly simpler…

da = [“Apr”, “2”, “2007”]
time = Time.parse(da.join(" "))
puts time.strftime(<<FMT)
\tday = %d
\tmonth = %m
\tyear = %y
FMT

END

Output:

day = 02
month = 04
year = 07

Morton G. wrote:

Yes, that’s better. But don’t you need a ‘require “time”’ at the
beginning? I needed it to make it work in my somewhat obsolescent
version of Ruby. Is it now part of the standard library?

I think my irb required time … (1.8.6).

On Jun 26, 2007, at 11:00 PM, Joel VanderWerf wrote:

FMT

Output:

day = 02
month = 04
year = 07

Yes, that’s better. But don’t you need a ‘require “time”’ at the
beginning? I needed it to make it work in my somewhat obsolescent
version of Ruby. Is it now part of the standard library?

Regards, Morton

Cool W. wrote:

DateArray = [“Apr”, “2”, “2007”]

How can i read the month and year in the array???

The OUTPUT:
day = 01
month = 04
year = 07

Hi,

For me worked like that:

tt = Time.parse(da.join(" “))
day = tt.strtime(”%d")
month = tt.strftime("%m")
year = tt.strftime("%y")

print “\nday #{day}”
“\nmonth #{month}”
“\nyear #{year}”
“\n”

Best regards,

Alin

On Jun 26, 8:50 pm, Cool W. [email protected] wrote:

The OUTPUT:
day = 01
month = 04
year = 07

I think you mean:
day = 01
month = 04
year = 2007

Have we learned nothing from Y2K?