I inherited a QMQUERY program that my user came to me today indicating that the week number was not correct. This query puts data into a workfile and a second query is called that splits other data into fields. As far as the two relevant fields are concerned, the second program does not modify them, just has them as part of the select statement. Pretty straight forward stuff. The relevant code in the select statement is this:
week(convdate(a.odudt)) as Week
The input data shows a.odudt = 1160624. The result in the file shows AsDueDate = 2016-07-01 and week = 30.
CONVDATE is a service program coded as follows (there is some testing for a valid date that I excluded, if the date is not valid it returns a null value.
CREATE FUNCTION qgpl/CONVDATE
DECLARE F_OUTPUT DATE;
SET F_OUTPUT = DATE(
SUBSTR(CHAR(19000000 + I_YMD),5,2) ||'/'||
SUBSTR(CHAR(19000000 + I_YMD),7,2) ||'/'||
SUBSTR(CHAR(19000000 + I_YMD),1,4)
Questions: why is this converting the date from 6/24 to 7/1? Why is the week coming up as 30?
Note: this is a single example, but is reported to be frequent issue.