Forum: Ruby on Rails Date formatting and adding question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adam J. (Guest)
on 2006-03-18 19:45
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!
Michael Kaiser (Guest)
on 2006-03-18 20:31
(Received via mailing list)
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/C...
http://api.rubyonrails.org/classes/ActiveSupport/C...

Michael
This topic is locked and can not be replied to.