Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

increment date attribute with 5 minute.

increment date attribute with 5 minute.

New Contributor

I have start ,end time named attribute as show below data . I am trying to add 5 minute using date format but keep getting exceptions due to illegal format exception. tried all options

EndTime 2017-04-15T10:10:00.666Z

StartTime 2017-04-15T10:05:00.666Z

{ "StartTime": "${StartTime:toDate("yyyy-mm-ddTHH:mm:ss.SSSZ"):toNumber():plus(300000):format("yyyy-mm-ddTHH:mm:ss.SSSZ")}", "EndTime": "${EndTime:toDate("yyyy-mm-ddTHH:mm:ss.SSSZ"):toNumber():plus(300000):format("yyyy-mm-ddTHH:mm:ss.SSSZ")}" }

{ "StartTime": "${StartTime:toDate("yyyy-mm-ddTHH:mm:ss.SSS'Z'"):toNumber():plus(300000):format("yyyy-mm-ddTHH:mm:ss.SSSZ")}", "EndTime": "${EndTime:toDate("yyyy-mm-ddTHH:mm:ss.SSSZ"):toNumber():plus(300000):format("yyyy-mm-ddTHH:mm:ss.SSSZ")}" }

getting exception .

1 REPLY 1
Highlighted

Re: increment date attribute with 5 minute.

Super Collaborator

@ashutosh pathak

The issue here is because of the Z literal on the date. You can handle it in the below expression

${start_date:replaceAll("Z$", "+0000"):toDate("yyyy-MM-dd'T'HH:mm:ss.SSSZ"):toNumber():plus(300000):toDate():format("yyyy-MM-dd'T'HH:mm:ss.SSSZ"):replace("+0000","Z")}

Refer the Java Date Format specs here.

EDIT

A cleaner way, I just stepped on pattern letter X

${start_date:toDate("yyyy-MM-dd'T'HH:mm:ss.SSSX"):toNumber():plus(300000):toDate():format("yyyy-MM-dd'T'HH:mm:ss.SSSX")}
Don't have an account?
Coming from Hortonworks? Activate your account here