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 > Sysdate

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-03, 08:37
mprog mprog is offline
Registered User
 
Join Date: Aug 2003
Posts: 6
Sysdate

Is there a way to give the SYSDATE a date.

Here is what I am trying to do, I have a functions that uses SYSDATE, and for testing purposes, I need the SQL database to think that the SYSDATE is Friday instead of today, Monday. Any help would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 09-23-03, 09:23
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Sysdate

You'd have to reset the system clock on the test server, I believe.

Alternatively: wrap SYSDATE in a packaged function, then you could adjust the returned value any way you like like this:

Code:
create or replace package utils as
  function currdate return date;
  procedure set_offset( p_offset in number );
end;
/

create or replace package body utils as
  g_offset number := 0;

  function currdate return date
  is
  begin
    return SYSDATE + g_offset;
  end;

  procedure set_offset( p_offset in number )
  is
  begin
    g_offset := p_offset;
  end;

end;
/
For example:

SQL> alter session set nls_date_format='DD-MON-YYYY HH24:MIS';

Session altered.

SQL> select sysdate, utils.currdate
2 from dual;

SYSDATE CURRDATE
-------------------- --------------------
23-SEP-2003 14:18:32 23-SEP-2003 14:18:32

SQL> exec utils.set_offset(-3)

PL/SQL procedure successfully completed.

SQL> /

SYSDATE CURRDATE
-------------------- --------------------
23-SEP-2003 14:18:47 20-SEP-2003 14:18:47

Of course, by doing this you are introducing a call to a PL/SQL function, which could impact performance if used heavily in SQL statements.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 09-26-03, 09:04
evanhattem evanhattem is offline
Registered User
 
Join Date: Sep 2003
Location: The Netherlands
Posts: 311
hi,

if you want 'select sysdate from dual' to return friday instead of monday, you 'll have to change dat and time of the database server and restart your database.

Hope this helps
__________________
Edwin van Hattem
OCP DBA / System analyst
Reply With Quote
  #4 (permalink)  
Old 10-08-03, 04:35
georgemarousi georgemarousi is offline
Registered User
 
Join Date: Oct 2003
Posts: 3
Re: Sysdate

HI,

You could use "SYSDATE-4"
instead of "SYSDATE"
so you would avoid changing your original sysdate.. would that do it for u?
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