If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Oracle PL/SQL Date Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-10-03, 12:50
mprog mprog is offline
Registered User
 
Join Date: Aug 2003
Posts: 6
Question 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.
Reply With Quote
  #2 (permalink)  
Old 09-10-03, 12:59
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
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.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On