db2 date format concat specific time
-
02-07-2021 - |
Frage
I'm trying to query data that happened between Yesterday 6 AM and Today 6 AM.
I'm having a problem in concatenation.
This is what I've tried.
Where update_time between date(CURRENT DATE,'mm/dd/yyyy 06:00:00')- 1 DAYS
and date(CURRENT DATE,'mm/dd/yyyy 06:00:00')
Lösung
Try this:
WHERE UPDATE_TIME
BETWEEN TIMESTAMP(CHAR(CURRENT DATE,ISO) || ' 06:00:00') - 1 DAY
AND TIMESTAMP(CHAR(CURRENT DATE,ISO) || ' 06:00:00')
Updated to answer X-Zero's comment:
The DB2 function CHAR(CURRENT DATE,ISO)
takes the current date, and converts it to a character string in the ISO
format. Taking today's date, the CHAR function would return "2012-09-18".
Next, we concatenate (||) a time string to the date string. The space in the time string creates a character DB2 timestamp in the correct format. "2012-09-18 06:00:00".
Finally, the DB2 function TIMESTAMP
takes the character DB2 timestamp and converts it to an actual DB2 timestamp.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow