Goal is to extract YYYY
from A.SCC_ROW_ADD_DTTM
with format of DateTm
Using peoplesoft Query Manager, adding an expression hoping to pull Year from a DateTm field.
Running a query on the DateTm field displays date in the following format: 03/19/2017 12:00:23PM
And so I tried
TO_CHAR(TO_DATE(A.SCC_ROW_ADD_DTTM, 'MM/DD/YYYY HH:MI:SSPM'), 'YYYY')
But keep getting the error not a valid month (50,380), but every date in the list starts with months in the format of XX (01-12). Full code below
SELECT A.ITEM_TYPE, B.DESCR, SUM( A.ITEM_AMT- A.APPLIED_AMT), TO_CHAR(TO_DATE(TO_CHAR(CAST((A.SCC_ROW_ADD_DTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF'), 'MM/DD/YYYY HH:MI:SSPM'), 'YYYY'), TO_CHAR(CAST((A.SCC_ROW_ADD_DTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF')
FROM PS_ITEM_SF A, PS_ITEM_TYPE_TBL B
WHERE ( B.ITEM_TYPE = A.ITEM_TYPE
AND ( A.ITEM_TYPE IN ('600000050010','600000050020','600000050030')
AND B.EFFDT =
(SELECT MAX(B_ED.EFFDT) FROM PS_ITEM_TYPE_TBL B_ED
WHERE B.SETID = B_ED.SETID
AND B.ITEM_TYPE = B_ED.ITEM_TYPE
AND B_ED.EFFDT <= SYSDATE) ))
GROUP BY A.ITEM_TYPE, B.DESCR, TO_CHAR(TO_DATE( TO_CHAR(CAST((A.SCC_ROW_ADD_DTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF'), 'MM/DD/YYYY HH:MI:SSPM'), 'YYYY'), A.SCC_ROW_ADD_DTTM
HAVING ( SUM( A.ITEM_AMT- A.APPLIED_AMT) > 0)
ORDER BY 1
I've tried changing the date format but get worse errors when changing from anything but what the expression is now, I just have no idea why it says the months are incorrect.
EDIT: I now notice that peoplesoft Query Manager automatically casts the field to a timestamp, there is no way to prevent this, and so I think there is no way to fix this.