Purpose
You can call this function to convert a CHAR, VARCHAR2, NCHAR, or NVARCHAR2 string into a value of the INTERVAL YEAR TO MONTH data type. This function can be used in the addition or subtraction of a date and time value.
Syntax
/*SQL date format*/
TO_YMINTERVAL([+-] years-months)
/*ISO date format*/
TO_YMINTERVAL([-]P[ years Y][months M][days D][T[hours H][minutes M][seconds[.frac_secs]S]])
Parameters
| Parameter | Description |
|---|---|
| [+-] years-months | A string of the CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type that complies with the parameter format.
|
| [-]P[ years Y][months M][days D][T[hours H][minutes M][seconds[.frac_secs]S]] | A string of the CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type that complies with the parameter format. frac_secs indicates the fractional part of seconds, which is an integer in the range of [0,999999999]. Notice Spaces are not allowed in the value. |
Return types
This function returns the INTERVAL YEAR TO MONTH data type.
Examples
Return the datetime value that is 1 year 2 months after the current date and time.
obclient> SELECT SYSDATE,SYSDATE+TO_YMINTERVAL('01-02') FROM DUAL;
+-----------+--------------------------------+
SYSDATE SYSDATE+TO_YMINTERVAL('01-02')
+-----------+--------------------------------+
18-NOV-21 18-JAN-23
+-----------+--------------------------------+
1 row in set