question

Nicholas M avatar image
0 Likes"
Nicholas M asked Nicholas M commented

Help with importing correct date and time from excel

Relatively new to FlexSim. I'm trying to run my simulation based off an imported schedule from Excel. I originally converted the start date/time to a number (IE 8/10/2021 7:49:48 PM became 44418.81) just so I could get the rest of the model logic to function. However, this logic did not accurately depict the actual time I needed the FlowItems to arrive. Now, I want to get the arrivals to actually show up on time but am having some trouble converting between Excel's values for DateTime and FlexSim's values.

The way I have it now, FlexSim just ignores the start time and causes all 634 arrivals to occur simultaneously. I was wondering if I'm just having a brain-fart as to which code to run / the correct way to convert to FlexTime or if using a Global Table to import this data would be the best option. Any help would be greatly appreciated!1629730485094.png

Import Data: Filtered Flexsim Data2.xlsx

FlexSim Model: ScheduledTime.fsm

FlexSim 21.1.5
FlexSim 21.2.0
excel importflexsim 21.2.0arrival scheduledatetime
5 |100000

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

1 Answer

Eric M avatar image
2 Likes"
Eric M answered Nicholas M commented

Hi @Nicholas McGrath, Flexsim has a DateTime class which can be used in converting times from Excel. You can either import the excel time as a number and use the fromExcelTime command or you can use the date string and use the DateTime constructor. The number that's returned in these commands is the number of seconds since Jan 1, 1601. I did this in your model using the script and GlobalTable1. The 2nd column can be copied into the arrivals source. Let me know if you have any questions!

scheduledtime-em.fsm


· 3
5 |100000

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

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hello @Nicholas McGrath,

The code Eric used in the script window to create a column of the values that FlexSim requires to properly introduce the tokens at the right time can be used in the "Post Import Code" with some slight modification.

1629748715408.png

Place the following in the post import code box

int onreset = param(1); //1 if this code is being called on Reset of the model, 0 otherwise
Table table = Table("ProcessFlow/Source (Schedule Source)");
DateTime ModelStart = Model.dateTime;  //get model start time as a number

for (int i = 1; i <= table.numRows; i++){
string StartTime = table[i][1];
DateTime date = DateTime(StartTime, "%m/%d/%Y %I:%M %p");  //get string as a number
table[i][1] = date - ModelStart;//calculate the difference between start time and arrival time in number of seconds
}

When you import your data to the schedule source it should show up in the correct number format.

scheduledtime-em-jf.fsm

2 Likes 2 ·
Nicholas M avatar image Nicholas M Jeanette F ♦♦ commented ·

@Jeanette F The global table isn't needed for this code to work correct? I've tried importing the data and running the code to recreate your example file and it's not changing the number format... I must be doing something improperly.

1629809286834.png


0 Likes 0 ·
1629809286834.png (124.9 KiB)
Nicholas M avatar image Nicholas M Nicholas M commented ·

Actually I figured it out! I had to change the table reference for some odd reason but it's working perfectly now. Thank you both for all your help!

  1. int onreset = param(1); //1 if this code is being called on Reset of the model, 0 otherwise
  2. Table table = Table(Model.find("Operator1/ProcessFlow/Source>variables/arrivals"));
  3. DateTime ModelStart = Model.dateTime; //get model start time as a number
  4. for (int i = 1; i <= table.numRows; i++){
  5. string StartTime = table[i][1];
  6. DateTime date = DateTime(StartTime, "%m/%d/%Y %I:%M %p"); //get string as a number
  7. table[i][1] = date - ModelStart;//calculate the difference between start time and arrival time in number of seconds
  8. }
1 Like 1 ·