From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: Fun with Dates
Date: Mon, 29 Oct 2012 23:44:01 +0100
Message-ID: <k6n0qf$c8f$1@ger.gmane.org> (raw)
In-Reply-To: <508F0576.4020404@noaa.gov>
References: <508F0576.4020404@noaa.gov>
Mark Fenbers wrote on 29.10.2012 23:38:
> Greetings,
>
> I want to be able to select all data going back to the beginning of
> the current month. The following portion of an SQL does NOT work,
> but more or less describes what I want...
>
> ... WHERE obstime >= NOW() - INTERVAL (SELECT EXTRACT (DAY FROM NOW()
> ) ) + ' days'
>
> In other words, if today is the 29th of the month, I want to select
> data that is within 29 days old... WHERE obstime >= NOW() - INTERVAL
> '29 days'
>
Or the other way round: anything that is equal or greater than the first
of the current month:
select ...
from foobar
where obstime >= date_trunc('month', current_date);
Thomas
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: Fun with Dates
In-Reply-To: <k6n0qf$c8f$1@ger.gmane.org>
* 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