Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Red face Unanswered: How to subtract days from timestamp variable

    Hi,
    My requirement is to subtract days from a timestamp variable.
    This is my Store proc. code:
    create or replace procedure test_date_proc ( IN LASTRUN TIMESTAMP, IN NO_DAYS_BEFORE INTEGER, OUT_EFF_RUN TIMESTAMP )

    LANGUAGE SQL
    BEGIN
    DECLARE LASTRUN TIMESTAMP;
    DECLARE NO_DAYS_BEFORE INTEGER;
    DECLARE OUT_EFF_RUN TIMESTAMP;

    set OUT_EFF_RUN= LASTRUN - NO_DAYS_BEFORE;

    END@

    One of the input variable is a timestamp, and the other is integer.
    I would like the output variable in TIMESTAMP.
    eg: 2012-09-06-16.56.42.117792 - 3 = 2012-09-03-16.56.42.117792

    How to write the SET statement for this? Thanks in advance.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    set OUT_EFF_RUN= LASTRUN - NO_DAYS_BEFORE DAYS

    Datetime operations and durations

    Why would you need a stored procedure for that though?
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

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