user1548157
user1548157

Reputation: 81

Get today's date in yyyy-mm-dd format in Pig

Is there a way where I can get today's date in Pig Script in yyyy-mm-dd format. I am unable to get hold of any API for that.

Thanks

Upvotes: 4

Views: 8242

Answers (2)

RCS
RCS

Reputation: 1432

You can use ToString(CurrentTime(),'yyyy-MM-dd') as date:chararray in your pig script.

Upvotes: 3

Ad Fundum
Ad Fundum

Reputation: 650

You can define a TODAYS_DATE variable like this:

%default TODAYS_DATE `date +%Y-%m-%d`;

and refer to it every time you need by inserting $TODAYS_DATE in the string:

'/data/mydata/$TODAYS_DATE'

Make sure to make no typing mistakes. You may also use %declare, but you will lose the flexibility to override the value from the command line or parameter file.

Upvotes: 4

Related Questions