From: | Steve Crawford <scrawford(at)pinpointresearch(dot)com> |
---|---|
To: | David Rickard <David(dot)Rickard(at)GTScompanies(dot)com>, pgsql-novice(at)postgresql(dot)org |
Cc: | Judith Strawser <judiths(at)GTScompanies(dot)com> |
Subject: | Re: Equivalent of Oracle next_day function |
Date: | 2003-10-14 00:14:55 |
Message-ID: | 200310131714.55507.scrawford@pinpointresearch.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I don't know of an equivalent but this should do what you want (this
gives you the preceding Sunday, add one to get Monday):
steve=# select current_date - date_part('dow', current_date)::int;
Make it a function if you like:
steve=# create function startofweek()
returns date
as
'select current_date - date_part(''dow'', current_date)::int+1'
language sql;
(note that's two single quotes not double quotes surrounding dow)
On Monday it will return the current Monday:
steve=#select startofweek();
startofweek
-------------
2003-10-13
Cheers,
Steve
On Monday 13 October 2003 4:28 pm, David Rickard wrote:
> Is there a postgres equivalent of Oracle's next_day() function? We
> have a web-based report that lists an employee's hours from Monday
> (of the current week) through the following Sunday (or sometimes
> the same period for the previous week); the beginning/end dates are
> retrieved (in Oracle) using the next_day function, ala:
>
> SELECT TO_CHAR ( ( NEXT_DAY ( SYSDATE, 'MONDAY' ) - 7 ),
> 'MM/DD/YY' ) AS THEMONDAY FROM DUAL
>
> What would be the simplest way to do this query in PostgreSQL?
>
>
>
> --
>
> David Rickard
> Software Engineer
> The GTS Companies
> A TechBooks Company
>
> -------------------------------------------------------------------
>---------------
>
> The GTS Companies:
> GTS Publishing Services, GTS Graphics, GTS Innova:
> Your Single-Source Solution!
> Los Angeles CA * York, PA * Boston MA * New Delhi, India
> -------------------------------------------------------------------
>---------------
>
>
>
> David(dot)Rickard(at)GTSCompanies(dot)com
> Visit us on the World Wide Web
> http://www.gtscompanies.com
> 5650 Jillson St., Los Angeles, CA 90040
> (323) 888-8889 x331
> (323) 888-1849 [fax]
From | Date | Subject | |
---|---|---|---|
Next Message | Systems Administrator | 2003-10-14 00:20:37 | SQL from PLPerl |
Previous Message | David Rickard | 2003-10-13 23:28:45 | Equivalent of Oracle next_day function |