TM1s.cfg parameter to have Excel serial dates
Posted: Sun Sep 10, 2023 11:44 pm
When we want to enable the use of Microsoft Excel serial dates instead of Planning Analytics serial dates, we would use UseExcelSerialDate=T in the TM1s.cfg file: https://www.ibm.com/docs/en/planning-an ... serialdate
However, this has implications, for instance on determining the day of the week (1 to 7, e.g.)
The typical way of calculating (also in Bedrock) is:
The 21915 offset is not easy to remember. It should just be a multiple of 7, then -2. So why not using 5 instead of 21915 ? Anyway we digress 
The above works fine for UseExcelSerialDate=F.
When UseExcelSerialDate=T, the logic breaks.
For instance today, 11 September 2023, is a Monday.
UseExcelSerialDate=F gives us 'MON', UseExcelSerialDate=T gives us 'SUN'.
Below I suggest 3 different ways to calculate the weekday (MON = 1, SUN = 7). All 3 are almost oneliners:
sDate is an example and can be changed for testing, looking in the text file.
This should work for both values of UseExcelSerialDate. Can others test this as well ? The code was only written today and it is a new insight as far as I am aware (Bedrock will also need adjusting if I am correct).
However, this has implications, for instance on determining the day of the week (1 to 7, e.g.)
The typical way of calculating (also in Bedrock) is:
Code: Select all
nDayIndex = Mod( DayNo ( sDate ) + 21915, 7 );
If( nDayIndex = 0 );
sWeekday = 'SUN';
ElseIf( nDayIndex = 1 );
sWeekday = 'MON';
ElseIf( nDayIndex = 2 );
sWeekday = 'TUE';
ElseIf( nDayIndex = 3 );
sWeekday = 'WED';
ElseIf( nDayIndex = 4 );
sWeekday = 'THU';
ElseIf( nDayIndex = 5 );
sWeekday = 'FRI';
ElseIf( nDayIndex = 6 );
sWeekday = 'SAT';
EndIf;

The above works fine for UseExcelSerialDate=F.
When UseExcelSerialDate=T, the logic breaks.
For instance today, 11 September 2023, is a Monday.
UseExcelSerialDate=F gives us 'MON', UseExcelSerialDate=T gives us 'SUN'.
Below I suggest 3 different ways to calculate the weekday (MON = 1, SUN = 7). All 3 are almost oneliners:
Code: Select all
sDate = '2023-09-11';
########################################################
# OPTION 1: the FormatDate function
########################################################
# Result: 1 = Sunday, ..., 7 = Saturday
nWeekday = Numbr( FormatDate( DayNo( sDate ), 'e', 0 ));
# Rework to: 1 = Monday, ..., 7 = Sunday
nWeekday = If( nWeekday = 1, 7, nWeekday - 1 );
AsciiOutput( 'test.txt', 'OPTION 1: ' | NumberToString( nWeekday ));
########################################################
# OPTION 2: the NumberToStringEx function
########################################################
# Result: 1 = Sunday, ..., 7 = Saturday
nWeekday = Numbr( NumberToStringEx( DayNo( sDate ) + 21916 - Dayno( '1960-01-01' ), 'w', '', '' ));
# Rework to: 1 = Monday, ..., 7 = Sunday
nWeekday = If( nWeekday = 1, 7, nWeekday - 1 );
AsciiOutput( 'test.txt', 'OPTION 2: ' | NumberToString( nWeekday ));
########################################################
# OPTION 3 the Mod function
########################################################
# Result: 0 = Sunday, ..., 6 = Saturday
nWeekday = Mod( DayNo( sDate ) + Dayno( '1960-01-01' ) / 21916 - 2, 7 );
# Rework to: 1 = Monday, ..., 7 = Sunday
nWeekday = If( nWeekday = 0, 7, nWeekday );
AsciiOutput( 'test.txt', 'OPTION 3: ' | NumberToString( nWeekday ));
This should work for both values of UseExcelSerialDate. Can others test this as well ? The code was only written today and it is a new insight as far as I am aware (Bedrock will also need adjusting if I am correct).