rose
rose

Reputation: 137

to find week begin date and week end date

i have a to the find week start date and end date for each date.

for eg: enter image description here

is it possible to achieve in IBM db2 and Hadoop ? available fields are date and week id

Upvotes: 0

Views: 463

Answers (1)

Ian Bjorhovde
Ian Bjorhovde

Reputation: 11052

You can use the DAYOFWEEK_ISO function (which returns the day of week of a date, where 1 = Monday):

with s (dt) as (
    values date('2021-10-27')
)
select
    dt,
    dt - dayofweek_iso(dt) + 1 days as beginning_dt,
    dt - dayofweek_iso(dt) + 7 days as end_dt
from s;


DT         BEGINNING_DT END_DT    
---------- ------------ ----------
10/27/2021 10/25/2021   10/31/2021

  1 record(s) selected.

Upvotes: 1

Related Questions