[Solved-2 Solutions] Get today's date in yyyy-mm-dd format in Pig ?




CurrentTime()

  • It returns the date-time object of the current time.

Problem:

Is there a way to get today's date in Pig Script in yyyy-mm-dd format ?

Solution 1:

  • We 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. We can also use % declare, but you will lose the flexibility to override the value from the command line or parameter file.

Solution 2:

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

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