1

I would like to extract the week in the year from a large dataset. I selected 'Add column based on this column' and used this script ' value.toDate("yyyy/mm/dd").datePart("weeks") '

See attached image

However the result is week in the month but not year.

Arky
  • 380
  • 1
  • 4
  • 15
  • 1
    I tried to transform the column to date with "value.toDate()" and then used this GREL "value.toDate('yyyy-mm-ddh:m:s').toString('w')". That seemed to work. – Arky May 27 '20 at 07:27
  • But we still got "week in month" using `value.toDate('y/m/d').toString('w')`. According to the [SimpleDateFormat patterns](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html), it should be "week in year". – Ettore Rizza May 27 '20 at 07:46

1 Answers1

1

More about this issue here. Until it is solved, could you switch to Python/Jython and use this script?

from datetime import datetime

date_time_obj = datetime.strptime(value, '%Y/%m/%d')

return date_time_obj.isocalendar()[1]

enter image description here

Ettore Rizza
  • 2,800
  • 2
  • 11
  • 23
  • 1
    Thank you for pointing to the bug. I tried an alternative workaround it seemed to work https://stackoverflow.com/questions/62036538/extracting-week-in-the-year-with-openrefine#comment109722916_62036538 – Arky May 27 '20 at 07:29
  • @Arky Nice catch! – Ettore Rizza May 27 '20 at 07:36