I have a simple timeclock application with an Admin page. I''m trying to find an easy way to select a range of record from the database. For instance "This week", "Last week", or "Last month" without having to manually calculate the dates. This is what I''ve come up with, but it does require me to manually calculate everything: startFrame = "2007-09-18" endFrame = "2007-09-20" @punches = Punch.find(:all, :conditions => [''timein > :startFrame AND timein < :endFrame'', {:startFrame => startFrame, :endFrame => endFrame}]) The variables are there so eventually the user can select their own date range. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Jason, please remember that the console is your friend. Thus, you can simply test it out in the console: @punches = Punch.find(:all, :conditions => [ ''timein >= ? AND timein <= ?'', startFrame, endFrame ] ) Good luck, -Conrad On 9/23/07, Jason Burgett <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I have a simple timeclock application with an Admin page. I''m trying to > find an easy way to select a range of record from the database. For > instance "This week", "Last week", or "Last month" without having to > manually calculate the dates. This is what I''ve come up with, but it > does require me to manually calculate everything: > > startFrame = "2007-09-18" > endFrame = "2007-09-20" > > @punches = Punch.find(:all, :conditions => [''timein > :startFrame AND > timein < :endFrame'', {:startFrame => startFrame, :endFrame => > endFrame}]) > > The variables are there so eventually the user can select their own date > range. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. The selection code is working fine. What I''m trying to avoid is having to manually calculate the values of startFrame and endFrame. Is there a method or something in rails to just say select all record within the last week but not prior to Sunday? So if it is Wednesday today I would get the records for Monday, Tuesday, and Wednesday. I know I can calculate the values with a bunch of code-fu but I''d like to avoid it if I can. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Jason, this link may be of assistance to you. http://www.rubyinside.com/advent2006/17-extendingar.html Good luck, -Conrad On 9/23/07, Jason Burgett <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Thanks for the reply. The selection code is working fine. What I''m > trying to avoid is having to manually calculate the values of startFrame > and endFrame. Is there a method or something in rails to just say select > all record within the last week but not prior to Sunday? So if it is > Wednesday today I would get the records for Monday, Tuesday, and > Wednesday. > > I know I can calculate the values with a bunch of code-fu but I''d like > to avoid it if I can. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Burgett wrote:> Thanks for the reply. The selection code is working fine. What I''m > trying to avoid is having to manually calculate the values of startFrame > and endFrame. Is there a method or something in rails to just say select > all record within the last week but not prior to Sunday? So if it is > Wednesday today I would get the records for Monday, Tuesday, and > Wednesday. > > I know I can calculate the values with a bunch of code-fu but I''d like > to avoid it if I can.Time.now.monday <<-- midnight on monday morning just do a Time.now.methods.sort. there are a whole load of useful methods. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---