pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Kalchev <daniel@digsys.bg>
To: Sandis <sandis@mediaparks.lv>
Cc: pgsql-sql@postgresql.org
Subject: Re: Extracting data by months
Date: Fri, 04 Aug 2000 16:24:01 +0300
Message-ID: <200008041324.QAA13602@dcave.digsys.bg> (raw)
In-Reply-To: <000a01bffde7$4bb21d20$d17b02c3@mediaparks.lv>

This is not exactly what the original question was about. You select the month 
is one specific year only.

What you do it however easier achieved by:

SELECT datums FROM jaunumi WHERE date_trunc('month', datums) = '2000-08-01';

datetime is an type full of tricks. :-)

Daniel

>>>"Sandis" said:
 > I do it like this:
 > 
 > SELECT datums FROM jaunumi
 > WHERE date_part('year',datetime(datums)) = '2000' AND
 >               date_part('month',datetime(datums)) = '08';
 > 
 > Where datums is a timestamp field.
 > 
 > Regards,
 > Sandis Jerics
 > www.mediaparks.lv
 > 
 > > This might seem rather silly, but could you simply do something like:
 > >
 > > select * from database
 > >        where date_field >= '01/01/2000'::date
 > >        and   date_field < '02/01/2000'::date;
 > >
 > > Of course, if date_field could contain many different years, then this
 > > would not get you the result you wanted.
 > >
 > > John
 > >
 > > On Thu, 3 Aug 2000, Antti Linno wrote:
 > >
 > > > Lo.
 > > >
 > > >  I'm in dire need of knowledge, how to extract data by month. Monthday
 > > > and year arent' important, those I can't give from perl script, but what
 > > > I do give to postgres are the numbers of the months. Date field is in
 > > > timestamp. I thought about date_trunc, but I can't think of, how to get
 > > > data with it. In script will be 12 queries, for each month, to get the
 > > > news from that month.
 > > > Btw, is there somewhere a manual about date_trunc, the docs that come
 > with
 > > > RH6.1 distribution are somewhat short and lacking explanation of
 > > > date_trunc.
 > > > Antti
 > > >
 > > >
 > >
 > 





view thread (6+ messages)  latest in thread

Message-ID: <200008041324.QAA13602@dcave.digsys.bg>
Permalink:  ../200008041324.QAA13602@dcave.digsys.bg/
Also on:    postgresql.org/message-id/200008041324.QAA13602@dcave.digsys.bg

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: daniel@digsys.bg, sandis@mediaparks.lv
  Subject: Re: Extracting data by months
  In-Reply-To: <200008041324.QAA13602@dcave.digsys.bg>
  References: <000a01bffde7$4bb21d20$d17b02c3@mediaparks.lv> <200008041324.QAA13602@dcave.digsys.bg>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox