Date Function for DB2

前端 未结 2 1196
长情又很酷
长情又很酷 2020-12-22 10:32

I have a file which has transaction details in DB2 and my requirement is extract last 1 months transaction data. Currently I amend the date range manually as bellow.

<
2条回答
  •  臣服心动
    2020-12-22 11:01

    How about using current date and date arithmetics?

    WHERE TRAN_DATE BETWEEN current date and (current date - 1 month)
    

    If you need the YYYYMMDD format, you can convert like this:

    YEAR(CURRENT DATE) * 10000 + MONTH(CURRENT DATE) * 100 + DAY(CURRENT DATE)
    

提交回复
热议问题