Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Posts
    6

    Question Unanswered: Oracle PL/SQL Date Function

    Hi,
    Can someone tell me how to write a date function for the following:

    AsOfDate = If Monday, current date - 3
    Else current date - 1

    The date needs to be displayed in mm/dd/yyyy format.

    Any help is greatly appreciated.

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Oracle PL/SQL Date Function

    Using DECODE:

    DECODE( TO_CHAR(SYSDATE,'DY'), 'MON', SYSDATE-3, SYSDATE-1 )

    Using CASE:

    CASE WHEN TO_CHAR(SYSDATE,'DY')='MON' THEN SYSDATE-3 ELSE SYSDATE-1 END

    In either case the result is of type DATE: use TO_CHAR to convert to required format when displaying.

Posting Permissions

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