Skip site navigation (1) Skip section navigation (2)

Re: Problem with selecting the first day of the the week

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "x asasaxax" <xanaruto(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with selecting the first day of the the week
Date: 2008-10-29 20:40:41
Message-ID: 162867790810291340y320390f3s31d94ffaa54110fb@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
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(at)gmail(dot)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!
>

In response to

pgsql-general by date

Next:From: Raymond O'DonnellDate: 2008-10-29 20:46:07
Subject: Re: Problem with selecting the first day of the the week
Previous:From: Kevin GalliganDate: 2008-10-29 20:18:28
Subject: Slow query performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group