diff --git a/core/sql/exp/exp_datetime.cpp b/core/sql/exp/exp_datetime.cpp index 926cde2401..6c1e8b0540 100644 --- a/core/sql/exp/exp_datetime.cpp +++ b/core/sql/exp/exp_datetime.cpp @@ -3686,6 +3686,8 @@ ExpDatetime::convDatetimeToASCII(char *srcData, { if (hour > 12) hour = hour - 12; + if ( 0 == hour ) + hour = 12; } convertToAscii(hour, dstDataPtr, 2); return (dstDataPtr - dstData); @@ -3809,10 +3811,8 @@ ExpDatetime::convDatetimeToASCII(char *srcData, int weekofmonth = 0; if ( day ) { - Int64 interval = getTotalDays(year, 1, 1); - int dayofweek = (int)(((interval + 1) % 7) + 1); int dayofyear = Date2Julian(year,month,day)-Date2Julian(year,1,1)+1; - weekofmonth = (dayofyear-1+dayofweek-1)/7+1; + weekofmonth = (dayofyear-1)/7+1; } convertToAscii(weekofmonth,dstDataPtr,2); return (dstDataPtr - dstData); diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp index 85a5fbf4af..1685b9c1b8 100644 --- a/core/sql/exp/exp_function.cpp +++ b/core/sql/exp/exp_function.cpp @@ -3034,6 +3034,11 @@ static Int64 lcl_interval(rec_datetime_field eField, Lng32 eCode, char *opdata, { short nValue; str_cpy_all((char *) &nValue, opdata, sizeof(nValue)); + if ( 0 == nValue ) + return 1; + nValue = nValue % 12; + if ( 0 == nValue ) + return 4; return (nValue-1)/3+1; } if ( REC_DATE_EPOCH == eField ) @@ -3173,11 +3178,9 @@ Int64 ex_function_extract::getExtraTimeValue(rec_datetime_field eField, Lng32 eC return year/10; } case REC_DATE_WEEK: - {//same with built-in function week ITM_WEEK - Int64 interval = datetimeOpType->getTotalDays(year, 1, 1); - Int64 dayofweek = lcl_dayofweek(interval); + { Int64 dayofyear = lcl_dayofyear(year,month,day); - return (dayofyear-1+dayofweek-1)/7+1; + return (dayofyear-1)/7+1; } case REC_DATE_QUARTER: {