Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2008
    Posts
    4

    Unanswered: date manipulation

    i'm preparing a stored procedure to manipulate a date datatype. Can somebody help me on how to list out all dates between 2 given dates. For example input 1 is '03/05/2008' and input 2 is '03/08/2008'.

    I need the result to be :

    '03/05/2008'
    '03/06/2008'
    '03/07/2008'
    '03/08/2008'

    Pls help.

  2. #2
    Join Date
    Aug 2005
    Posts
    140
    Code:
    create function datumy (dat1 date,dat2 date)
    returning set(date not null);
    define diff integer;
    define i integer;
    define datmn set(date not null);
    let diff=dat2-dat1;
    let diff=diff -1;
    for i in (1 to diff step 1)
    insert into table(datmn) values(dat1+i);
    end for
    
    return datmn;
    end function;

    hope this helps

  3. #3
    Join Date
    Oct 2008
    Posts
    4

    date manipulation

    Thank you.

    But instead of inserting the result into a table can I list the result straight away. This is because I need to execute the procedure/function in the client application, I don't want to call another table to get the result.

    Thanks.

  4. #4
    Join Date
    Aug 2005
    Posts
    140
    AFAIK this is not possible with SPL. It actually doesn't fall into philosophy of stored procedures.

  5. #5
    Join Date
    Oct 2008
    Posts
    4
    ok, thank you. i will work out on this.

  6. #6
    Join Date
    Oct 2008
    Posts
    3

    stored procedure

    stored procedure to manipulate a date datatype. Can somebody help me on how to list out all dates between 2 given dates. For example input 1 is '03/05/2008' and input 2 is '03/08/2008

  7. #7
    Join Date
    Jul 2008
    Posts
    8
    Maybe something like this,
    add code to validate from_date >= to_date;

    create procedure blah (
    from_date date,
    to_date date)
    returning date;

    define return_date date;

    let return_date = from_date;

    while (return_date <= to_date)

    return return_date;

    let return_date = return_date + 1 units day;

    end while;

    end procedure;


Posting Permissions

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