question

Swami Premnidhi avatar image
0 Likes"
Swami Premnidhi asked Matthew Gillespie answered

changing start date and time using code

Hii, Try to take the start date and time from the global table using custom code.

code used :-

string startDate = Table("GlobalTable1")[1][1];

string Date = startDate+ " " + "06:00:00";

DateTime newStartTime = DateTime(Date, "%d/%m/%Y %I:%M:%S");

treenode startNode = getmodelunit(START_TIME_NODE);

startNode.value = newStartTime.value;

applicationcommand("convertunixtime", startNode, startNode.value);


It is not working.

Attached model for reference. Support1.fsm

Thanks in advance.



FlexSim 21.1.2
custom codeglobaltabledatetime
support1.fsm (30.2 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered

In 21.1 the model start and stop times are stored differently. To update the start time in 21.1 and later use this code:

DateTime startTime = DateTime("9/11/2020 07:00:00", "%m/%d/%Y %I:%M:%S");
function_s(getmodelunit(START_TIME_NODE), "setDateTime", startTime);
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Roi Sánchez avatar image
0 Likes"
Roi Sánchez answered Swami Premnidhi commented

HI @Swami Premnidhi, you could try to construct the DateTime variable in another way:

DateTime newStartTime = DateTime.compose(2021, 03, 24, 23, 45, 00);
treenode startNode = getmodelunit(START_TIME_NODE); 
startNode.value = newStartTime.value; 
applicationcommand("convertunixtime", startNode, startNode.value);
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Swami Premnidhi avatar image Swami Premnidhi commented ·

Hi @Roi Sánchez,

Thanks for the reply. The code you have given me is not converting the model start date and time to the date and time I inserted in the code. Instead, it is changing the model date and time to Jan 1601 which is not expected. Can you take a look at the attached model? Sample Model DateTime.fsm

Regards,

Swami Premnidhi



0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.