Re: Weeks elapsed to Months elapsed conversion

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: <pgsql-sql(at)postgresql(dot)org>, "Allan Kamau" <allank(at)sanbi(dot)ac(dot)za>
Subject: Re: Weeks elapsed to Months elapsed conversion
Date: 2008-05-30 14:56:28
Message-ID: 484031BB.A3DD.0030.0@indicator.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Approx. 52 weeks in a year, thus 13 weeks in 3 months.

select numberofweeks/13*3 as numberofmonths
from yourtable

or if you want whole months returned
select floor(numberofweeks/13*3) as numberofmonths
from yourtable

>>> Allan Kamau <allank(at)sanbi(dot)ac(dot)za> 2008-05-30 11:21 >>>
Hi all,
I have a simple question (tried googling but found no answers). How do I
convert weeks elapsed into months elapsed?
I have data that contains duration in weeks (without any other date
values such as year and so on) for example a week value of 14 and I
would like to convert the 14 weeks to 3 months (some lose of accuracy
expected).
Expected tests may be:
14 weeks yields 3 months.
1 weeks yields 0 months.

Is there such a function. The rudimentary solution (may reduce lose of
accuracy) am thinking of is to add the weeks to the value returned by
clock_timestamp() then subtract clock_timestamp() from it. The question
now is how to convert the returned value to months elapsed as opposed to
days elapsed.

Allan.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2008-05-30 15:13:47 Re: Weeks elapsed to Months elapsed conversion
Previous Message Allan Kamau 2008-05-30 09:21:41 Weeks elapsed to Months elapsed conversion