Hi, I am trying to sort a a chart of my database entries. I would like to sort by weekday, date, & time. I want to be able to do each separately. I would like to be able to process this through the find ''sql'' the order by. This might sound a little confusing but the goal is to be able to sort the data by the weekday, date, or time. Please let me know if you can help or you have any questions. Thanks, Nathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, I am trying to sort a a chart of my database entries. I would like to sort by weekday, date, & time. I want to be able to do each separately. I would like to be able to process this through the find ''sql'' the order by. This might sound a little confusing but the goal is to be able to sort the data by the weekday, date, or time. Please let me know if you can help or you have any questions. Thanks, Nathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So you want all the Sunday entries first, and then sorted by regular date/time w/in Sunday, then all the Monday entries, and so forth? Does your db server have a weekday() function? -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Biles Online Sent: Friday, May 02, 2008 2:44 PM To: Ruby on Rails: Talk Subject: [Rails] split datetime into 3 Hi, I am trying to sort a a chart of my database entries. I would like to sort by weekday, date, & time. I want to be able to do each separately. I would like to be able to process this through the find ''sql'' the order by. This might sound a little confusing but the goal is to be able to sort the data by the weekday, date, or time. Please let me know if you can help or you have any questions. Thanks, Nathan --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How would I know if my db server has a weekday function? To output the data I am using strftime("%A") for the weekday --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Heh--you''d check the docs. What db are you using? I can tell you MySQL has a weekday function. So if you were using that you could do e.g., YourModel.find(:all, :order => ''weekday(your_date), your_date'') -Roy On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote:> How would I know if my db server has a weekday function? To output the > data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, I''m using mysql. I''ll try that. What about just the date and time? I need to do the same thing with weekday but with time of day. On May 2, 6:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Heh--you''d check the docs. What db are you using? I can tell you > MySQL has a weekday function. So if you were using that you could do > e.g., > > YourModel.find(:all, :order => ''weekday(your_date), your_date'') > > -Roy > > On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > How would I know if my db server has a weekday function? To output the > > data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How exactly does the weekday function work? my column I need to convert is ''datetime'' On May 2, 6:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Heh--you''d check the docs. What db are you using? I can tell you > MySQL has a weekday function. So if you were using that you could do > e.g., > > YourModel.find(:all, :order => ''weekday(your_date), your_date'') > > -Roy > > On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > How would I know if my db server has a weekday function? To output the > > data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, so I figured out the weekday. THANKS A LOT!!!!! : ) On May 2, 6:22 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote:> How exactly does the weekday function work? > > my column I need to convert is ''datetime'' > > On May 2, 6:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Heh--you''d check the docs. What db are you using? I can tell you > > MySQL has a weekday function. So if you were using that you could do > > e.g., > > > YourModel.find(:all, :order => ''weekday(your_date), your_date'') > > > -Roy > > > On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > > How would I know if my db server has a weekday function? To output the > > > data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Took a wild guess that I can use: :order => ''time(datetime), datetime'' it worked. Thanks for all your help! On May 2, 6:27 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote:> Ok, so I figured out the weekday. THANKS A LOT!!!!! : ) > > On May 2, 6:22 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > How exactly does the weekday function work? > > > my column I need to convert is ''datetime'' > > > On May 2, 6:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Heh--you''d check the docs. What db are you using? I can tell you > > > MySQL has a weekday function. So if you were using that you could do > > > e.g., > > > > YourModel.find(:all, :order => ''weekday(your_date), your_date'') > > > > -Roy > > > > On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > > > How would I know if my db server has a weekday function? To output the > > > > data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If you want to have the db do it (which I suspect will be most efficient) you''ll want to use other db functions for that. http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Biles Online Sent: Friday, May 02, 2008 4:19 PM To: Ruby on Rails: Talk Subject: [Rails] Re: split datetime into 3 Yeah, I''m using mysql. I''ll try that. What about just the date and time? I need to do the same thing with weekday but with time of day. On May 2, 6:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Heh--you''d check the docs. What db are you using? I can tell you > MySQL has a weekday function. So if you were using that you could do > e.g., > > YourModel.find(:all, :order => ''weekday(your_date), your_date'') > > -Roy > > On May 2, 4:10 pm, Biles Online <i...-BBTgu1wt7e9fOZc0+OmrVg@public.gmane.org> wrote: > > > How would I know if my db server has a weekday function? To output > > the data I am using strftime("%A") for the weekday--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This my way in this case: @bill_pays = BillPay.find(:all) @sorted_by_time = @bill_pays.sort_by{|x| x.paid_at.strftime(''%H:%M:%S'')} @sorted_by_date = @bill_pays.sort_by{|x| x.paid_at.strftime(''%d/%m/%Y%'')} for bill in @bill_pays if bill.paid_at.strtime(''%W'').to_i > 5 @bill_pays = @bill_pays - bill.to_a end end @sorted_by_weekday = @bill_pays.sort_by{|x| x.paid_at} Sorry I can not answer in find_by_sql, maybe other people here will answer. Good Luck, Reinhart http://teapoci.blogspot.com -- 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 -~----------~----~----~----~------~----~------~--~---