Re: [SQL] function year!

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Jerome Knobl <jknobl(at)mandanet(dot)ch>, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] function year!
Date: 1998-08-17 09:28:52
Message-ID: l03110703b1fda5b259e3@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 11:59 +0300 on 17/8/98, Jerome Knobl wrote:

> Hello,
>
> I have a timestamp value, and I'm tring to get only the year, the month
> or the day.
> I'm using the function now() to put some value inside.
>
> I tried the function year(..) (select year(thedate) from mytable;)
>
> but that function are not define! I'm looking for a simple way to get my
> informations?

You want the year, the month, and the day.

So, define a separate function for each interesting part? A bit of a waste,
isn't it? There is a function "date_part()", which accepts two arguments -
one is a text saying which part you want, and one is the data itself.

Note that it is defined on the datetime type. So if you want to use
timestamp, you will have to convert it, like:

date_part( 'year', datetime( my_timestamp ) )

As usual, I recommend using the type datetime, not timestamp, in your table.

More information about the date_part() function is in the pgbuiltin man page.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Roy Sigurd Karlsbakk 1998-08-18 14:40:16 The use of sequences
Previous Message Jerome Knobl 1998-08-17 09:21:03 How create an index on a timespamp col!