Convert 6 digit date to 8 digit

779 views Asked by At

I have a | delimited file, which has values like 150330, which represents date. To standardize, I need to convert this values as 2015-03-30. I need to do it in Pig, due to few more conversions.

Tried ToDate & DateTime functions, without any luck.

Any suggestion?

2

There are 2 answers

0
Ravinder Karra On

you can use pig function in following way

B = foreach A GENERATE SUBSTRING(ToString(ToDate('150330','yyMMdd')),0,10);

output is (2015-03-30)

0
glefait On

If you need to convert "150330" into "2015-03-30", this is not a date problem but rather String manipulation

  1. use SUBSTRING to get 15, 03, 30
  2. use CONCAT to join all the substring.

However, as said @murali-rao, you have to know if your dealing with 19xx or 20xx dates.