from sqlalchemy.sql import func
query = model.MyClass.query.order_by(func.date(model.MyClass.created_at))

This applies the sql "date" function to the column. That function
definitely exists in mysql; I'm not sure if it is standard, but if not
I'm sure you can find an equivalent function for whatever rdbms you
are using.

On Mon, Mar 9, 2009 at 9:12 PM, BruceC <i...@coble.com.au> wrote:
>
> Hi all,
>
> I have a table with a column called created_at which is a datetime
> field. I'm trying to construct a query where I would like the results
> ordered by just the date portion of the datetime field, but I can't
> find any reference to the correct syntax for such a query.
>
> This works:
>
> query = model.MyClass.q.order_by(model.MyClass.created_at).all()
>
> ...but it's not what I'm after. I need to order by only the date & not
> by the date and time.
>
> Does anybody have any tips on how to do this?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to