0

我在 db2 中有这样的日期:1950-01-31。我希望得到一年前的日期对应(即 1949-01-31)。我从中得到提示:

current date + 1 YEAR 
current date + 3 YEARS + 2 MONTHS + 15 DAYS 
current time + 5 HOURS - 3 MINUTES + 10 SECONDS

我尝试:

select dateCol-1 year FROM table, 

但它给了我 1950-01-30。看起来它总是从一天而不是一年中减去 1。我怎样才能得到一年前的日期。

4

1 回答 1

0
select date(days(dateCol)-(case when month(dateCol)=2 and day(dateCol)=29 then 366 else 365 end)) from table


db2 => values (date(days('28.02.2004')-(case when month(dateCol)=2 and day(dateCol)=29 then 366 else 365 end)))
>  2003-02-28
1 record(s) selected.

db2 => values (date(days('29.02.2004')-(case when month(dateCol)=2 and day(dateCol)=29 then 366 else 365 end)))
>  2003-02-28
1 record(s) selected.
于 2013-10-30T16:26:10.250 回答