sMonth = ( MONTH ( TODAY ) ) ;

Product:
Planning Analytics 2.0.9.18
Microsoft Windows 2019 server

Issue:
How get the month before today?

Solution:

In TM1 TI code you can write something similar to this in prolog:

## sMonth = 1 ;
## remove sMonth = below and test with above line

sMonth = ( MONTH ( TODAY ) ) ;
sYear = ( YEAR (TODAY) ) ;
IF ( sMonth = 1) ;
pMonth = numbertostring ( 12 ) ;
pYear = sYear - 1;
ELSE ;
pMonth = numbertostring (sMonth - 1 ) ;
pYear = sYear ;
ENDIF ;

IF (LONG (pMonth) = 1) ;
p2Month = '0' | pMonth ;
ELSE ;
p2Month = pMonth ;
ENDIF ;

pVersion = (p2Month) | ' - ' | numbertostring(pYear) ;

ASCIIOUTPUT ( 'd:\temp\debugtestdate.txt', numbertostring (sMonth) , numbertostring(sYear) , (p2Month) , numbertostring(pYear) ) ;

Will give a test file with this result:

 

If you want to have the year in 4 digits, you can add it like this;

IF ( sMonth = 1) ;
pMonth = numbertostring ( 12 ) ;
pYear = '20' | numbertostring ( sYear - 1 ) ;
ELSE ;
pMonth = numbertostring (sMonth - 1 ) ;
pYear = '20' | numbertostring ( sYear ) ;
ENDIF ;

 

 

More Information:

https://www.ibm.com/docs/en/planning-analytics/2.0.0?topic=dtrf-month

Dates and Time in TM1