how to find whether a day, is weekend

S

Srikanth Jeeva

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
 
D

David Rio Deiros

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
 
S

Srikanth Jeeva

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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top