pig tutorial - apache pig tutorial - Apache Pig - MonthsBetween(datetime1, datetime2) Function - pig latin - apache pig - pig hadoop
What is MonthsBetween(datetime1,datetime2) function in Apache Pig ?
- The MonthsBetween(datetime1,datetime2) function will accept the two date-time objects and also calculates the number of months which is done between the two given date-time objects.
- The MonthsBetween(datetime1,datetime2) function will returns the number of months which is done between date-time datetime1 and datetime2.
- The MonthsBetween(datetime1,datetime2) calculates the fractional portion of the result and also considers the difference of the time components which is given between datetime1 and datetime2.
Syntax
Example
- Ensure that there is a file named wikitechy_doj_dob.txt in the HDFS directory /pig_data/.
- The file contains the date-of-birth details and date-of-joining details of a particular person, id, dateof-birth and date-of-joining.
wikitechy_doj_dob.txt
- We have loaded the file into Pig with a relation name doj_dob_data which is given below:
- We can calculate the number of minutes which is done between date-of-birth and date-of-joining of the employees by using the MonthsBetween() function which is given below:
Verification
- We need to verify the contents of the relation by using the Dump operator which is given below:
Output
- The above statement stores the result in the relation named monthsbetween_data