Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This article is posted on the CDAP Doc wiki and will be maintained here: https://cdap.atlassian.net/wiki/spaces/DOCS/pages/1224900611/Calculating+time+between+Timestamps

This document describes how to calculating different units of time between two timestamps using Wrangler. For example, a user may want to calculate the number of months between two calendar dates. This assumes the columns are already timestamps. If they are strings, use the parse-as-simple-date directive to parse the string into a timestamp.

...

As of 6.4.0, there is no out of the box directive for this, so the set-column directive must be used to calculate the year difference. This can be done as:

set-column :year_diff dt1.getYear() - dt2.getYear()

where year_diff is the name of a new column, and the dt1 and dt2 columns are the names of the timestamps that are being subtracted.

...

As of 6.4.0, there is no out of the box directive for this, so the set-column directive must be used to calculate the month difference. This can be done as:

set-column :month_diff 12 * (dt1.getYear() - dt2.getYear()) - + (dt1.getMonthValue() - dt2.getMonthValue())

where month_diff is the name of a new column, and the dt1 and dt2 columns are the names of the timestamps that are being subtracted.

...

As of 6.4.0, there is no out of the box directive for this, and also no simple way to calculate this with so the set-column directive must be used. This can be done as:

set-column :day_diff date:DAYS_BETWEEN(dt1, dt2)

Page Properties
hiddentrue

Related issues