Re: Dividing (and rounding) a date?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neal Lindsay <neal(dot)lindsay(at)peaofohio(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Dividing (and rounding) a date?
Date: 2001-07-31 15:14:03
Message-ID: 10864.996592443@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Neal Lindsay <neal(dot)lindsay(at)peaofohio(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Neal Lindsay 2001-07-31 16:53:17 Re: Dividing (and rounding) a date?
Previous Message Richard Huxton 2001-07-31 14:54:15 Re: Get name of columns in a table