question

David Seo avatar image
0 Likes"
David Seo asked David Seo commented

how to convert simulation time() to weekday as number?

I am using FlexSim update 2.

I want to know how to convert the simulation running time() to weekday as number not string.

During running FlexSim model, I should get the weekday as number like followed;

Monday => 1, Tuesday => 2, Wednesday => 3....Sunday => 7.

I should use weekly repeated table in patient route and examination distribution like followed;

I want to know how to convert time() to the repeated weekday number as 1,2,3,4,5,6,7 from Moday or starting 0 time.

FlexSim HC 5.3.10
FlexSim 19.1.2
to weekday as numberweekday as number
5 |100000

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

Steven Hamoen avatar image
2 Likes"
Steven Hamoen answered David Seo commented

@Seung Yong Seo

What I usually do is create a global variable called weekdays and make a userevent that fires every 86400 seconds (24 hours) and increase the global variable. When the number becomes 8 I make it 1 again.

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

David Seo avatar image David Seo commented ·

Thanks, @steven.hamoen

That's a good idea.

0 Likes 0 ·
Mischa Spelt avatar image
1 Like"
Mischa Spelt answered David Seo commented

If you only need the value in one or two places, you could do the calculation on the fly.

time() / hours(24) will give you the amount of days elapsed, when you take this modulo seven you get 0, 1, ..., 6. So if the start of the model is on Monday (day 1), the following should also work:

(int)(time() / hours(24)) % 7 + 1
· 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.

David Seo avatar image David Seo commented ·

Thanks @Mischa Spelt.

Perfect!

0 Likes 0 ·
Patrick Zweekhorst avatar image
0 Likes"
Patrick Zweekhorst answered David Seo commented

Hi @Seung Yong Seo,

You mention that you are working in FlexSim Update 2, but your version shows FlexSim HC.
If you are working with FlexSim and not HC you can use

Model.dateTime.dayOfWeek

As command the ask for the current day of the week in your simulation. This command does not exist in HC I think.

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

David Seo avatar image David Seo commented ·

Thank you @Patrick Zweekhorst.

Yes. I could find the DayOfWeek command in the DateTime class. But 1 is Sunday not Monday. Another conversion script is needed. Thanks anyway.

0 Likes 0 ·