question

kauan pedroso avatar image
0 Likes"
kauan pedroso asked Jeanette F commented

How to filter a date and time

Hello !

I have a DBconnector that takes data from SQL Server and pulls it into flexsim. I would like to know if it is possible to filter this table by day and time filter, so that my list is not so heavy.

1679664114820.png


FlexSim 21.2.4
global tabledatabasesql server
capture-123.png (14.6 KiB)
1679664114820.png (44.4 KiB)
· 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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @kauan pedroso, was Luis Gustavo Freitas's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Luis Gustavo Freitas avatar image
0 Likes"
Luis Gustavo Freitas answered Jeanette F commented

Hello Kauan,

I would need to see your model to know what can be done. For now, I recommend you to use the DateTime functions the way you're using to create columns that will be used to filter, something like SET a Month Column and filter it normally.

· 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.

kauan pedroso avatar image kauan pedroso commented ·

Hello @Luis Gustavo Freitas

I can't share my file, but I can show the script that pulls the data. I would like to filter the date InputTimestamp.



0 Likes 0 ·
Luis Gustavo Freitas avatar image Luis Gustavo Freitas kauan pedroso commented ·

Hello Kauan, I've been working in a solution that might be close to what you need.

Here i'm using a query to import the dbConnector by Custom Code. This code compare the date column of the database "Arrivals" (that is in Excel format in this case) whitin the current Model Time and pulls just 1 week of data to GlobalTable1.

Database.Connection dbConn = Database.Connection("db_Historic");

//Query pulls and order the Arrivals in interval of 7 days based on Model DateTime
dbConn.query("SELECT * FROM input_2022 WHERE Arrivals BETWEEN " + string.fromNum(Model.dateTime.excelTime) + " AND " + string.fromNum(Model.dateTime.excelTime + 7) + " ORDER BY Arrivals ASC").cloneTo("GlobalTable1");

By that you can execute this code as many times you need and decrease your model's weight. Depending on your database time format you might need to use other functions of Model.dateTime to adapt the query.


0 Likes 0 ·
kauan pedroso avatar image kauan pedroso Luis Gustavo Freitas commented ·

Hello Luis, I tried to adapt your code to mine and ended up giving error.

1680022596780.png

1680022622231.png

0 Likes 0 ·
1680022596780.png (14.1 KiB)
1680022622231.png (9.9 KiB)
Show more comments