split datetime into 3


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.


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?

How would I know if my db server has a weekday function? To output the
data I am using strftime("%A") for the weekday

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

  YourModel.find(:all, :order => 'weekday(your_date), your_date')


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.

How exactly does the weekday function work?

my column I need to convert is 'datetime'

Ok, so I figured out the weekday. THANKS A LOT!!!!! : )

Took a wild guess that I can use:

:order => 'time(datetime), datetime'

it worked. Thanks for all your help!

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.