Re: Dividing (and rounding) a date? - Mailing list pgsql-novice

From Tom Lane
Subject Re: Dividing (and rounding) a date?
Date
Msg-id 10864.996592443@sss.pgh.pa.us
Whole thread Raw
In response to Dividing (and rounding) a date?  (Neal Lindsay <neal.lindsay@peaofohio.com>)
Responses Re: Dividing (and rounding) a date?
List pgsql-novice
Neal Lindsay <neal.lindsay@peaofohio.com> writes:
> I am trying to create a query that, given a date, will return the
> beginning-of-pay-period date.  Our pay periods last two weeks and begin on
> Mondays.  I can't seem to divide or find the modulus of any date or
> interval types.  Does anyone have any suggestions?

Hmm, I see how to get back to the most-recent Monday:

regression=# select now()::date - date_part('dow', now()) + 1;
  ?column?
------------
 2001-07-30
(1 row)

but there's no date_part function that would give you two-week
intervals.  I think you'll have to use date_part('epoch') to extract
the time as a Unix timestamp (seconds since 1-1-1970), do arithmetic
on that, and cast the result back to an SQL timestamp.  Ugh.

            regards, tom lane

pgsql-novice by date:

Previous
From: Joel Burton
Date:
Subject: Re: ----??? Random ???
Next
From: Neal Lindsay
Date:
Subject: Re: Dividing (and rounding) a date?