Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

apache-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

like image 308
user1548157 Avatar asked Mar 19 '23 14:03

user1548157


2 Answers

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.

like image 134
Ad Fundum Avatar answered Apr 06 '23 05:04

Ad Fundum


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

like image 42
RCS Avatar answered Apr 06 '23 05:04

RCS