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
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
On Dec 9, 2008, at 9:37 PM, Srikanth J. wrote:
[0,6].include?(date.wday)
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
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…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs