# Split datetime into 3

**URL:** <https://www.ruby-forum.com/t/split-datetime-into-3/196665>\
**Category:** Rails\
**Created:** [May 3, 2008, 12:59pm UTC](https://www.ruby-forum.com/t/split-datetime-into-3/196665 "2008-05-03T12:59:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Biles\_Online](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Biles\_Online](https://www.ruby-forum.com/u/Biles_Online)\
**Post date:** [May 3, 2008, 12:59pm UTC](https://www.ruby-forum.com/t/split-datetime-into-3/196665/1 "2008-05-03T12:59:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Biles\_Online](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Biles\_Online](https://www.ruby-forum.com/u/Biles_Online)\
**Post date:** [May 3, 2008, 2:40pm UTC](https://www.ruby-forum.com/t/split-datetime-into-3/196665/2 "2008-05-03T14:40:22Z")

</div>

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](http://teapoci.blogspot.com)
