Problem with selecting the first day of the the week

Started by x asasaxaxover 17 years ago3 messagesgeneral
Jump to latest
#1x asasaxax
xanaruto@gmail.com

Hi,

I need a function to select the first day of the week. For example
giving today´s date(29/10/2008).

Can anyone help´s me?
Thanks!

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: x asasaxax (#1)
Re: Problem with selecting the first day of the the week

Hello

try

CREATE OR REPLACE FUNCTION public.fdow(date)
RETURNS date
LANGUAGE sql
IMMUTABLE STRICT
AS $function$ select $1 - extract(dow from $1)::int $function$

postgres=# select fdow(current_date);
fdow
------------
2008-10-26
(1 row)

regards
Pavel Stehule

2008/10/29 x asasaxax <xanaruto@gmail.com>:

Show quoted text

Hi,

I need a function to select the first day of the week. For example
giving today´s date(29/10/2008).

Can anyone help´s me?
Thanks!

In reply to: x asasaxax (#1)
Re: Problem with selecting the first day of the the week

On 29/10/2008 20:11, x asasaxax wrote:

I need a function to select the first day of the week. For example
giving today�s date(29/10/2008).

select 'Monday';

;-)

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------