Date formatting and adding question

Hey all,

I’m working on a site for a client that has a scedule im trying to
display that pulls the next events for the upcoming Sunday from a MySQL
table…The table stores the event date as mm/dd/yyyy. I’ve tried to
think of everyway possible to get this thing to change after every
sunday to show the next sunday’s events, but I end up doing it
manually…

Is it possible to add to DateTime.now and find WHERE the date in the
database equals that…might sound confusing but i’ve seen this done in
ColdFusion easily like this:

SELECT * FROM Schedule
WHERE eventdate >= #DateFormat(DateAdd(“d”, 7, Now()), “mm/dd/yy”)#

Is it possible to do something like that in RoR?

Thanks in advance!

Hey,

I am not sure if I completely understand your question, but yes, you can
do arithmetics with dates.

Time.now.next_week would be the beginning of the upcoming week, so
1.day.until(Time.now.next_week) would give you the next sunday. Once you
have your date you can use it as a condition in your find.

You can look it up here:
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html

Michael