Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ruby question about getting a date 1

Status
Not open for further replies.

netooi25

Programmer
Jul 30, 2004
25
US
Hi, I'm fairly new to Ruby and need to get a date

Basically I need to get the next wednesday stored in a date variable..

If today is wednesday then it would store today, otherwise it would keep going to the next day until it was wednesday...

I tried a few little things using cwday which is part of the date class but couldnt get it to work, not sure if i'm just messing up syntax or what..

Thanks for any help..
Netooi
 
If you need to get a date, stop programming and go meet some people!

Haha.

Seriously, if you need the next Wednesday, wouldn't this work?

Code:
require 'date'

class Date
def next_wednesday
  return self + ((3 - self.wday) % 7) 
end
end

irb> Date.today.next_wednesday.to_s
=> "2006-04-12"

Hope this helps.

-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top