简体   繁体   中英

get the date along with year and month

The date condition below is good for fetching current year and current month I would like to add current date to it ,please append the query to get current date .

If (( Extract ( Month, current_date )) = 1)
Then ( Cast ( ( Cast((( Extract (Year, current_date) -1)), varchar(4))  || '12'), int) ) 
Else ( If ((Extract ( Month, current_date) -1) < 10 )
           Then ( Cast(( ( Cast ((Extract ( Year, current_date )), varchar(4)))  || '0' ||  ( Cast (( Extract ( Month,  current_date) - 1), varchar(2)))), int)  ) 
           Else ( Cast ((  Cast ((Extract ( Year, current_date  )), varchar(4))  || ( Cast(( Extract ( Month, current_date) - 1), varchar(2)))), int)  )
)

thanks in advance

Your code is Cognos right? I can't help you there, but in DB2, this will get you current year, current month and current date.

values (year(current date), month(current date), current date)

eg it will return

1    2 3
---- - ----------
2018 3 2018-03-21

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM