How to find whether a day, is weekend


#1

hi, can any one give me the idea.,
how to find whether a given date is a weekend, that is saturday or
sunday.
is there any inbuilt methods or we have to write the code.
Thanks…

Regards,
Srikanth J


#2

On Dec 9, 2008, at 9:37 PM, Srikanth J. wrote:

[0,6].include?(date.wday)

a @ http://codeforpeople.com/


#3

On Wed 10.Dec’08 at 13:37:28 +0900, Srikanth J. wrote:

hi, can any one give me the idea.,
how to find whether a given date is a weekend, that is saturday or
sunday.
is there any inbuilt methods or we have to write the code.

What about … ?

require ‘date’

class Date
def weekend?
self.wday == 0 || self.wday == 6
end
end

d1 = “9 December 2008”
d2 = “13 December 2008”

p Date.parse(d1).weekend? # false
p Date.parse(d2).weekend? # true

-drd


#4

Thanks a lot all…

require ‘date’
d1 = Date.new( 2008, 11, 1 )
d2 = Date.new( 2008, 12, 31 )

WEEKDAY_NUMBERS = [1,2,3,4,5]
weekdays = (d1…d2).select{ |d| WEEKDAY_NUMBERS.include?( d.wday ) }
p weekdays.length

i did with this code…