changing start date and time using code

changing start date and time using code

swami_p2
Not applicable
18 Views
3 Replies
Message 1 of 4

changing start date and time using code

swami_p2
Not applicable

[ FlexSim 21.1.2 ]

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.



0 Likes
Accepted solutions (1)
19 Views
3 Replies
Replies (3)
Message 2 of 4

roi_sn
Not applicable

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);
0 Likes
Message 3 of 4

swami_p2
Not applicable

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
Message 4 of 4

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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);


Matthew Gillespie
FlexSim Software Developer