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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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
Kent OlsenDBACommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hraja77Author Commented:
how would i call this function ?

thanks
H
0
Kent OlsenDBACommented:
Just like any other function.  :)

  SELECT getcurrentsysdate() from sysibm.sysdummy1;



Kent
0
hraja77Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.