Re: get week from date/datetime field
Posted in 2003
Pohoda wrote:
> Hi,
>
> I have a very basic quesetion but I can't find
> any answer by myself. Is it possible to extract
> number of week from date/datetime column?
I don't think there is a built-in function that does this.
Look for anything by Jonathan Leffler in the IIUG FAQ or software archives
or the news group archives.
A quick and dirty procedure might look something like this:
------------------------------------------------------------------------
CREATE PROCEDURE week_no(idate DATE)
RETURNING SMALLINT;
RETURN TRUNC (
(
idate
-MDY(12, 31, YEAR(idate)-1)
+WEEKDAY(MDY(12, 31, YEAR(idate)-1))
)/7
+0.99
);
END PROCEDURE -- week_no
------------------------------------------------------------------------
This handles DATEs & DATETIMEs, but gives you 53 weeks and I'm sure doesn't
follow any ISO rules for week number calculation. ;-)
Cheers,
--
Mark.
+----------------------------------------------------------+-----------+
| Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /|
| Mydas Solutions Ltd http://MydasSolutions.com |///// / //|
| +-----------------------------------+//// / ///|
| |We value your comments, which have |/// / ////|
| |been recorded and automatically |// / /////|
| |emailed back to us for our records.|/ ////////|
+----------------------+-----------------------------------+-----------+
sending to informix-list