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
LVL 1
hraja77Asked:
Who is Participating?
 
Kent OlsenData Warehouse Architect / DBACommented:

Hi hraja,

You need a semicolon (';') after the RETURN statement.

And because it looks like you're trying to create the function in the CLP, you'll need to invoke the CLP with a different delimiter.  i.e.  db2 -td@


Good Luck,
Kent
0
 
PeteEngineerCommented:
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:
0
 
PeteEngineerCommented:
You can try this one

db2 select current date from sysibm.sysdummy1

sysibm.sysdummy is the "Oracke dual" for DB2.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
momi_sabagCommented:
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
0
 
hraja77Author Commented:
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
0
 
hraja77Author Commented:
how would i call this function ?

thanks
H
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Just like any other function.  :)

  SELECT getcurrentsysdate() from sysibm.sysdummy1;



Kent
0
 
hraja77Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.