On 09/21/2010 02:00 PM, Dave Fowler wrote:
> Hi,
>
> I'm new to SQLAlchemy but I've read the entire oreilly book and done a
> lot of googling and i've found that there is support for the generic
> functions
>
> current_date, current_time and current_timestamp
>
> but i can find nothing for finding the year, or week of a date
> column.
>
> I need them in order to group results by week or year depending on the
> user input.
>
>
> Does current_year and current_week exist somewhere?  And if not is
> there a way to create your own custom functions based on Column
> types?  I've yet to run into any documentation on that processes
> either.
>
> Thanks!
>   

Every DB has its own method for extracting parts out of a datetime. Here
are a few:

    * PostgreSQL [1]: extract('ISOYEAR', some_timestamp_expr),
      extract('WEEK', some_timestamp_expr)
    * MySQL [2]: func.year(some_timestamp_expr),
      func.week(some_timestamp_expr), func.yearweek(some_timestamp_expr)
    * SQLite [3]: func.strftime('%Y-%W', some_timestamp_expr). I do not
      believe you get correct ISO year-week behavior here, so beware.

-Conor

[1]
http://www.postgresql.org/docs/8.4/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
[2] http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
[3] http://www.sqlite.org/lang_datefunc.html

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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