pig tutorial - apache pig tutorial - Apache Pig - YearsBetween() - pig latin - apache pig - pig hadoop
What is YearsBetween() Function?
- YearsBetween returns the number of whole years between ANow and AThen.
- This number is an approximation, based on an average number of days of 365.25 per year (average over 4 years).
- This means the fractional part of a year is dropped.
Learn apache pig - apache pig tutorial - Apache Pig Years Between - apache pig examples - apache pig programs
YearsBetween() function in Apache Pig
This function accepts two date-time objects and calculates the number of years between the two given date-time objects.
- Ensure that we have a file named wikitechy_doj_dob.txt in the HDFS directory /pig_data/.
- This file contains the date-of-birth and date-of-joining details of a particular person, id, date of-birth and date-of-joining.
- We have loaded this file into Pig with a relation named doj_dob_data as given below.
- Now you can calculate the number of years between date-of-birth and date-of-joining of the employees using the YearsBetween() function as given below.
- Verify the contents of the relation using the Dump operator as given below.
- The above statement stores the result in the relation named yearsbetween_data.