All Forums Database
karver 17 posts Joined 01/09
01 Feb 2009
Manipulating 2-digit year

Anyone know how i can get the 2 digit year (also with the flexibility to say add 1, or 2 years to it?)It's easy enough to find the year (4 digits) but I can't get around to computing the year and getting only the last 2 digits. I have tried the following but it doesn't work:selectextract (year from (Add_months (current_date, 12))) (char (2))select substr( (extract (year from current_date) +1), 3, 2)

Fred 1096 posts Joined 08/04
01 Feb 2009

The result of EXTRACT is INTEGER, with default FORMAT '-(10)9'.If you want the result in CHAR format, just use two CASTs; the first just specifies the conversion format and the second actually converts the datatype:SELECTCAST(CAST(ADD_MONTHS(CURRENT_DATE, 12) AS FORMAT 'yy') AS CHAR(2))

karver 17 posts Joined 01/09
01 Feb 2009

This worked perfectly, Thanks Fred Pluebell!

You must sign in to leave a comment.