Results 1 to 2 of 2

Thread: Week Number

  1. #1
    Join Date
    Dec 2011
    Posts
    82

    Unanswered: Week Number

    Hello

    I was wondering if someone could kindly tell me how I calculate Week Number from a date field

    I.e. date field = AdmissionDate

    I am new to informix and am struggling with this

    Many Thanks for any help

  2. #2
    Join Date
    Sep 2011
    Location
    Pont l'Abbé, Brittany, France
    Posts
    381
    Provided Answers: 1
    Hi Helen,

    Basically, here is the code, authored by Jacques 'Mr Datablades' Roy.

    Code:
    CREATE FUNCTION week_of_year(dt date)
    RETURNS integer
    WITH(NOT VARIANT)
    
    DEFINE day1 date;
    DEFINE nbdays int;
    
    LET day1 = MDY(1, 1, YEAR(dt));
    LET nbdays = dt - day1;
    
    RETURN 1 + (nbdays + WEEKDAY(day1)) / 7;
    
    END FUNCTION;
    I will highly recommand you to read his paper regarding dates handling, which is also an excellent demo of what you can do with your own custom functions:

    check here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •