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
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
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.
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
CREATE FUNCTION GETCURRENTSYSDATE()
RETURNS CHAR(8)
DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
BEGIN ATOMIC
RETURN CHAR(YEAR(current date))||char(month(current
END
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
RETURNS CHAR(8)
DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
BEGIN ATOMIC
RETURN CHAR(YEAR(current date))||char(month(current
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how would i call this function ?
thanks
H
thanks
H
Just like any other function. :)
SELECT getcurrentsysdate() from sysibm.sysdummy1;
Kent
SELECT getcurrentsysdate() from sysibm.sysdummy1;
Kent
ASKER
thanks