pig tutorial - apache pig tutorial - Apache Pig GetDay(datetime) Function - pig latin - apache pig - pig hadoop

What is GetDay(datetime)function in Apache Pig ?

  • The GetDay(datetime) function will accept a date-time object as a parameter and return the current day of the given date-time object.
  • The GetDay() method returns the day of the week for the specified date which is given in GetDay() method.
  • The GetDay() gets the day of the month which is represented by this instance.


grunt> GetDay(datetime)


  • Ensure that we have a file named wikitechy_date.txt in the HDFS directory /pig_data/ as given below.
  • This file contains the date-of-birth details of a particular person, id, date, and time.


111,1990/09/26 09:00:00
112,1981/06/20 10:22:00
113,1991/12/19 03:11:44
  • We have loaded this file into Pig with a relation named date_data as given below.
grunt> date_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_date.txt' USING PigStorage(',')
   as (id:int,date:chararray);
  • Following is an example of the GetDay() function.
  • The GetDay() function will retrive the day from the given Date-Time object. So, first of all, let us calculate the date-time objects of all employees using todate() function as shown below.
grunt> todate_data = foreach date_data generate ToDate(date,'yyyy/MM/dd HH:mm:ss')
   as (date_time:DateTime );
grunt> Dump todate_data;
  • Now, get the day from the date-of-birth using GetDay() function and store it in the relation named getday_data.
grunt> getday_data = foreach todate_data generate(date_time), GetDay(date_time);


  • Verify the contents of the getday_data relation using the Dump operator.
grunt> Dump getday_data;



Related Searches to Apache Pig GetDay(datetime) Function