Skip to content
Advertisement

Select the first day and last day of this year in DB2

How to get the first day and the last day for the current year in DB2 in format YYYYMMDD?

I tried:

And:

But it does not work till I put the year, but I need the year to be a parameter “not need to change it every year in the Query”

Advertisement

Answer

You could do:

Demo on DB Fiddle:

FIRST_DAY_OF_THE_YEAR | LAST_DAY_OF_THE_YEAR
--------------------: | -------------------:
           2020-01-01 |           2020-12-31

If you want the results as strings in YYYYMMDD format, you can format the results with to_char():

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement