Vishakha
Vishakha

Reputation: 1

Pig Latin yyyyww

I want to convert year-week (yyyyww) in Pig to yyyyMMdd to get the first date of a given week. This is what I am trying and getting weird output.

ToString(ToDate('20171102', 'yyyyMMdd'), 'yyyyww') as c1

returns 201744. Which means 02-Nov-2017 is in 44th week of the year 2017. But when I do other way round, the output is weird.

ToString(ToDate('201744', 'yyyyww'), 'yyyyMMdd')

returns 20161031. Which says that the first date of 44th week of the year 2017 is 31-Oct-2016.

What am I doing wrong here?

Upvotes: 0

Views: 40

Answers (1)

Murali Rao
Murali Rao

Reputation: 2287

For 2017, week 44 is from Oct 30 to Nov 05.

In the first case as Nov 2nd falls btw Oct 30 to Nov 05, you are seeing the week as 44.

In the second case you are seeing the start day of the week, which is what you are looking for.

Upvotes: 0

Related Questions