DaysBetween in Pig gives wrong result for the month of March

I'm trying to convert a Vertica request to Pig which basically defines the number of days between two dates. When I converted the code and tried to use the DaysBetween function in PIG, it gives different output only for the month of March.

PIG result:

Y = FOREACH X GENERATE
(DaysBetween((datetime)ToDate('2015-04-01'),ToDate('2015-03-01')));
Output:- (30)

      

Vertica result:

SELECT JULIAN_DAY('2015-04-01')-JULIAN_DAY('2015-03-01');
Output:- (31)

      

When I checked the same for other months of the year, I don't get any errors.

PIG result:

Y = FOREACH X GENERATE
(DaysBetween((datetime)ToDate('2015-03-04'),ToDate('2015-02-04')));
Output:- (28)

      

Vertica result:

SELECT JULIAN_DAY('2015-03-04')-JULIAN_DAY('2015-02-04');
 Output :- 28

      

I cannot find the reason for the difference. Give some tips on how to solve the problem.

+3


source to share


1 answer


Specifying the timezone in UTC or GMT will help.



Y = FOREACH X GENERATE
(DaysBetween((datetime)ToDate('2015-04-01', 'yyyy-MM-dd', 'UTC'),ToDate('2015-03-01', 'yyyy-MM-dd', 'UTC')));

      

0


source







All Articles