*** a/src/backend/utils/adt/timestamp.c --- b/src/backend/utils/adt/timestamp.c *************** *** 3645,3650 **** timestamptz_age(PG_FUNCTION_ARGS) --- 3645,3651 ---- { /* form the symbolic difference */ fsec = fsec1 - fsec2; + tm->tm_gmtoff = tm1->tm_gmtoff - tm2->tm_gmtoff; tm->tm_sec = tm1->tm_sec - tm2->tm_sec; tm->tm_min = tm1->tm_min - tm2->tm_min; tm->tm_hour = tm1->tm_hour - tm2->tm_hour; *************** *** 3652,3657 **** timestamptz_age(PG_FUNCTION_ARGS) --- 3653,3667 ---- tm->tm_mon = tm1->tm_mon - tm2->tm_mon; tm->tm_year = tm1->tm_year - tm2->tm_year; + /* + * Currently all the DST changes hour changes, so we can directly + * add the DST difference to hours calculation. + * + * The drawback in this approach is that, sometimes it may give + * result as 24:00:00 instead of 1 day. + */ + tm->tm_hour += -(tm->tm_gmtoff / (MINS_PER_HOUR * SECS_PER_MINUTE)); + /* flip sign if necessary... */ if (dt1 < dt2) {