S
Srikanth Jeeva
want only the working hours(9am-5pm) between two dates, weekends should
be omitted..
i did this code..
require 'time'
require 'date'
class Date
def calc(date1,date2)
d1=Time.parse(date1).strftime('%d').to_i
m1=Time.parse(date1).strftime('%m').to_i
y1=Time.parse(date1).strftime('%Y').to_i
t1=Time.parse(date1).strftime('%H').to_i
min1=Time.parse(date1).strftime('%M').to_i
date1 = Date.new( y1, m1, d1 )
d2=Time.parse(date2).strftime('%d').to_i
m2=Time.parse(date2).strftime('%m').to_i
y2=Time.parse(date2).strftime('%Y').to_i
t2=Time.parse(date2).strftime('%H').to_i
date2 = Date.new( y2, m2, d2 )
weekdays = (date1..date2).reject { |d| [0,6].include? d.wday }
w= weekdays.length
working_hours=w*8
puts "working hours = #{working_hours}"
end
end
d=Date.new
d.calc("November 5th, 2008, 10:30 am","November 7th, 2008, 6:00 pm")
i have calculated the total working hours..
but i need the total hours between 9am-5pm, between the given dates..
can any one plz help??
thanks.,
Regards,
Srikanth J
be omitted..
i did this code..
require 'time'
require 'date'
class Date
def calc(date1,date2)
d1=Time.parse(date1).strftime('%d').to_i
m1=Time.parse(date1).strftime('%m').to_i
y1=Time.parse(date1).strftime('%Y').to_i
t1=Time.parse(date1).strftime('%H').to_i
min1=Time.parse(date1).strftime('%M').to_i
date1 = Date.new( y1, m1, d1 )
d2=Time.parse(date2).strftime('%d').to_i
m2=Time.parse(date2).strftime('%m').to_i
y2=Time.parse(date2).strftime('%Y').to_i
t2=Time.parse(date2).strftime('%H').to_i
date2 = Date.new( y2, m2, d2 )
weekdays = (date1..date2).reject { |d| [0,6].include? d.wday }
w= weekdays.length
working_hours=w*8
puts "working hours = #{working_hours}"
end
end
d=Date.new
d.calc("November 5th, 2008, 10:30 am","November 7th, 2008, 6:00 pm")
i have calculated the total working hours..
but i need the total hours between 9am-5pm, between the given dates..
can any one plz help??
thanks.,
Regards,
Srikanth J