pig tutorial - apache pig tutorial - Apache Pig - WeeksBetween() - pig latin - apache pig - pig hadoop

What is WeekBetween() Function?

  • WeeksBetween returns the number of whole weeks between ANow and AThen.
  • This means the fractional part of a Week is dropped.
 Apache Pig Weeks Between

Learn apache pig - apache pig tutorial - Apache Pig Weeks Between - apache pig examples - apache pig programs

WeeksBetween() function in Apache Pig

  • This function accepts two date-time objects and calculates the number of weeks between the two given date-time objects.


grunt> WeeksBetween(datetime1, datetime2)


  • 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.


001,26/09/1989 09:00:00,16/01/2015 09:00:00
002,20/06/1980 10:22:00,10/08/2011 09:00:00
003,19/12/1990 03:11:44,25/10/2012 09:00:00 
  • We have loaded this file into Pig with a relation named doj_dob_data as given below.
grunt> doj_dob_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_doj_dob.txt' USING PigStorage(',')
   as (id:int, dob:chararray, doj:chararray);
  • Now you can calculate the number of weeks between date-of-birth and date-of-joining of the employees using the WeeksBetween() function as given below.
grunt> weeksbetween_data = foreach wikitechy_doj_dob_data generate WeeksBetween(ToDate(doj,
   'dd/MM/yyyy HH:mm:ss'),ToDate(dob,'dd/MM/yyyy HH:mm:ss'));


  • Verify the contents of the relation using the Dump operator as given below.
grunt> Dump weeksbetween_data;


  • The given statement stores the result in the relation named weeksbetween_data.

Related Searches to Apache Pig Weeksbetween

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.