Link to home
Start Free TrialLog in
Avatar of hraja77
hraja77

asked on

need a function to display the current system date

hi,

i need a function in db2 which when i call will always return the current system/server date in the format 'YYYMMDD'

please help - new to db2

thanks
H
Avatar of PeteEngineer
PeteEngineer
Flag of India image

The CURRENT DATE special register gives the current system date and CURRENT TIMESTAMP the current system date and time. This can be used in select statements or more directly using the VALUES statement:
You can try this one

db2 select current date from sysibm.sysdummy1

sysibm.sysdummy is the "Oracke dual" for DB2.
try

CREATE FUNCTION GETCURRENTSYSDATE()
     RETURNS CHAR(8)
     DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
     BEGIN ATOMIC
     RETURN CHAR(YEAR(current date))||char(month(current date))||char(day(current day))
   END
Avatar of hraja77
hraja77

ASKER

CREATE FUNCTION GETCURRENTSYSDATE()
     RETURNS CHAR(8)
     DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
     BEGIN ATOMIC
     RETURN CHAR(YEAR(current date))||char(month(current date))||char(day(current day))
   END

this gives the errors


DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "END" was found following "r(day(current day))
".  Expected tokens may include:  "<delim_semicolon>".  LINE NUMBER=5.  
SQLSTATE=42601
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hraja77

ASKER

how would i call this function ?

thanks
H
Just like any other function.  :)

  SELECT getcurrentsysdate() from sysibm.sysdummy1;



Kent
Avatar of hraja77

ASKER

thanks