Extracting date parts from datetime with postgresql

600 views
Skip to first unread message

laurent rahuel

unread,
Jan 22, 2007, 5:49:05 PM1/22/07
to sqlal...@googlegroups.com
Hi,

Here is my little trouble. I want to extract some parts of a datetime
field in a postgresql database.

I played around with the func.year(), func.month() but it sounds like
postgresql doesn't understand the resulting query. For example, a
func.year() call is converted into :

select year(myDateTime) from mytable;

This works with MySQL but not with Postgresql. The error is "function
year(timestamp without time zone) doesn't exist"

I guess the resulting Postgresql query should be :

select EXTRACT (year FROM myDateTime) from mytable;

Any clue ???

Regards,

Laurent

Jonathan Ellis

unread,
Jan 22, 2007, 6:07:35 PM1/22/07
to sqlal...@googlegroups.com
date_part is a synonym for extract w/ more normal syntax

so you could write func.date_part('year', mydatetime)

laurent rahuel

unread,
Jan 22, 2007, 6:32:01 PM1/22/07
to sqlal...@googlegroups.com
Great job, this is what I needed !!!

Regards,

Laurent

Jonathan Ellis a écrit :

Reply all
Reply to author
Forward
0 new messages