From: | Allan Engelhardt <allane(at)cybaea(dot)com> |
---|---|
To: | "Brian C(dot) Doyle" <bcdoyle(at)mindspring(dot)com> |
Subject: | Re: First Saturday and Last Saturday of a month |
Date: | 2001-08-08 22:18:32 |
Message-ID: | 3B71BAB8.3C2F114E@cybaea.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Brian C. Doyle" wrote:
> Hello all,
>
> I have a Function that gives me the fsunday of a week Based on the date you
> give it the select looks like
> SELECT Date('now') - timespan( text( date_part( 'dow', Date('now') ) ) ||
> 'days' )
> and if you run that today you will get
> ?column?
> ------------------------
> 2001-08-05 00:00:00-04
> (1 row)
>
> Which is what I want it to do ...
>
> Now I need to setup a function that will give me the first Saturday of the
> month and then one to get the Last Saturday of the month.
It's too late to hack code, but:
For the first Saturday problem assign
select date_part('dow', 'yyyy-mm-01'::DATE);
to a variable x. Here yyy and mm is the year and month you are interested in. The day you want is 'yyyy-mm-01' + [(6-x) days].
Getting all the conversions right is left as an exercise for the reader :-)
Last Saturday problem is similar to above except for some sign reversals, but more interesting as you need the number of days in the month. I think you'll have to calculate that (for February) the hard way :-P You *do* know the algorithm for testing if year yyyy is a leap year, don't you? ((yyyy%4) && !(yyyy%400))
Allan.
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-08-08 23:21:11 | Re: ERROR: AlterTableAddConstraint: |
Previous Message | Lee Harr | 2001-08-08 22:15:20 | ERROR: AlterTableAddConstraint: |