Skip to content
Advertisement

DB2 z/OS – Get the last 2 digits of year

SELECT
     SUBSTR(CAST(YEAR(SOMEDATE) AS VARCHAR(4)),2,2) AS "YY" 
FROM SOMESCHEMA.FOO;

Gets me the following error:

  1. [Code: -104, SQL State: 42601] ILLEGAL SYMBOL “,2”. SOME SYMBOLS THAT MIGHT BE LEGAL ARE:. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.26.14
  2. [Code: -514, SQL State: 26501] THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=4.26.14

And no matter what I change, the error stays..

Advertisement

Answer

The solution for DB2 z/OS is:

VARCHAR_FORMAT(SOMEDATE, 'YY') AS "YY"
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement