| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Allan Kamau <allank(at)sanbi(dot)ac(dot)za> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Weeks elapsed to Months elapsed conversion |
| Date: | 2008-05-30 15:13:47 |
| Message-ID: | 484019AB.4060002@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Allan Kamau wrote:
> 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.
Are these stored as intervals?
=> SELECT extract(month from justify_days('14 weeks'::interval));
date_part
-----------
3
(1 row)
=> SELECT extract(month from justify_days('1 week'::interval));
date_part
-----------
0
(1 row)
If you just have a number (e.g. 14) then you can just do something like:
=> SELECT round(14 * 7 / 30);
round
-------
3
(1 row)
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fernando Hevia | 2008-05-30 16:22:08 | Re: Weeks elapsed to Months elapsed conversion |
| Previous Message | Bart Degryse | 2008-05-30 14:56:28 | Re: Weeks elapsed to Months elapsed conversion |