Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETDATE() method for DB2

I have been trying for a while now to get a similar method to GETDATE() in DB2 for i. So far I have found the following:

current date
current timestamp
current time

Would it be possible for me to:

 select specific, columns
 from table
 where datefield = current date - 1 day

Is this the most efficient way or is there some way I perhaps haven't found yet?

EDIT:

I currently have this:

WHERE datefield = - days(date('2013-10-28'))

although this isn't helpful as I will need to edit it every day the query runs.

Have now come to this:

WHERE datefield = VARCHAR_FORMAT(CURRENT TIMESTAMP, 'YYYYMMDD') - 1

Except this will not work on the first day of the month as 1 - 1 = 0 and there is no day 0 in a month...

like image 835
DeanMWake Avatar asked Oct 30 '13 09:10

DeanMWake


People also ask

Is date function in DB2?

The DATE function returns a date that is derived from a value. The schema is SYSIBM. The argument must be an expression that returns one of the following built-in data types: a date, a timestamp, a character string, a graphic string, or any numeric data type.

What is DB2 Sysdate?

SYSDATE is a synonym for CURRENT TIMESTAMP when Db2-server is running on Linux/Unix/Windows, or on Z/OS.

What does Getdate () mean?

The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.


Video Answer


1 Answers

This will give you yesterday's date:

SELECT CURRENT DATE - 1 DAY FROM sysibm.sysdummy1
like image 107
Benny Hill Avatar answered Sep 21 '22 03:09

Benny Hill