question

Kevin S7 avatar image
0 Likes"
Kevin S7 asked Jason Lightfoot commented

error in code when changing from date and time to seconds


Greetings community I have a problem when importing an Excel I have a date and time and I want to convert those Excel input data to seconds in my global table but it gives me very high values which should not be, what could be wrong in my code? import source

1698158740317.png


The times must go to seconds regardless of when the simulation starts running and be able to change the start date and time of the simulation.

code of import


int onreset = param(1); //1 if this code is being called on Reset of the model, 0 otherwise

Table table = Table(Model.find("llegadas (Global Table"));

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 "); //get string as a number

table[i][1] = date - ModelStart;//calculate the difference between start time and arrival time in number of seconds

}



timw.fsm

FlexSim 23.2.1
time table
1698158740317.png (102.8 KiB)
timw.fsm (56.0 KiB)
· 4
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

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Jason Lightfoot commented

In Excel, Dates and Times often look like text, but they are usually stored as numbers. If I import your excel data without changing anything, I get the following data:

1698183417193.png

Notice that all the date values are around 45000. Excel date/times are stored as the number of days since 1900.

FlexSim DateTime objects, on the other hand, count the number of seconds since 1601 (or maybe 1600, I can't recall).

So, knowing this, it is incorrect to try to use the text of the Excel data. Instead, you can use the number. To convert between Excel time and FlexSim time, you can use the convert() command:

  1. DateTime date = DateTime(convert(StartTime, XL_DATETIME, FS_DATETIME));

But there are other problems as well:

  • The global table "llegadas" has a space after the name. It is best not to use trailing whitespace like that.
  • To access a global table, you just need the following syntax:
    1. Table table = Table("llegadas");
  • To access the start time as a date time, use
    1. Model.startDateTime

Those are all the issues I've found so far. See if you can get somewhere making those changes. Best of luck!


1698183417193.png (11.5 KiB)
· 9
5 |100000

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