Pretto
Pretto

Reputation: 467

Find weekday of date

I need to find the weekday of the 28th day of the year and month given. For test data:

1999-5
1998-6

I expect:

MONDAY
TUESDAY

Below is my solution:

date = []
2.times {date << gets.chop.split("-")}
for i in 0..1 do
  time = Time.new(date[i][0], date[i][1], 28)
  puts time.strftime("%^A")   # get Weekday
end

It returns

FRIDAY
SUNDAY

What I'm doing wrong with this?

Upvotes: 0

Views: 150

Answers (1)

AJcodez
AJcodez

Reputation: 34236

The code is working. May 28th, 1999 was a Friday.

source: http://en.wikipedia.org/wiki/May_1999

Upvotes: 2

Related Questions