How do I convert an h:mm:ss string value into minutes?

How do I convert an h:mm:ss string value into minutes?

tee_hiett
Not applicable
201 Views
5 Replies
Message 1 of 6

How do I convert an h:mm:ss string value into minutes?

tee_hiett
Not applicable

[ FlexSim 21.2.4 ]

In the posting, @Felix Möhlmann got me going with DATE_TIME values but I'm having diffficulty implementing his suggestions. In the attached model, TKC Endoscopy 040522_1.fsm.jpg, I am trying to get the time the patient was scheduled to arrive, which is in string h:mm:ss format, into minutes. The String label on the patient is patient.OriginalSchHM in the Arrivals Table. Note that this is not the time of the arrival of the patient but the time the patient was scheduled to arrive, usually much earlier than the patient's arrival time. This is in the activity Assigned Labels.

This converted value in minutes will be put into a patient label patient.OriginalSeqMins

Any help will be welcome.


0 Likes
Accepted solutions (1)
202 Views
5 Replies
Replies (5)
Message 2 of 6

moehlmann_fe
Enthusiast
Enthusiast
Accepted solution

What part of my suggestion in the other post are you having trouble with?

Instead of defining a script label in the table you can also read the scheduled time when assigning a label though the source activity.

1664182099251.png

If you want to continue working with the string time, then the way to convert it into a minute value is to use the DateTime constructor again, just the other way around. Pass in the string, define the format and it will give back the date time value. Since the date time is defined is seconds you then have to convert it to minutes.

DateTime dateTime = DateTime(patient.OriginalSeqHMS, "%H:%M:%S");
double minuteTime = dateTime.as(double)/getmodelunit(TIME_MULTIPLE); 

Though this will return the number of minutes since midnight, since the date is not specified. As such, the model time and the time in minutes from this conversion will be different if you run the simulation for longer than a day. Which is why I originally suggested to read the values directly from the schedule.


To use the "convert" command, the time string has to be in the format specified in the model settings. For your model that would be "hh:mm:ss AM/PM".

1664182360109.png

You can of course change the setting.

1664182472866.png1664182504606.png

58953-tkc-endoscopy-040522-1_1.fsm

0 Likes
Message 3 of 6

tee_hiett
Not applicable

Thanks for the prompt and helpful response. I am beginning to see the value of getting the time value from the arrivals table but when I tried to replicate your statement, I got the error message is shown here:

Errors in statement.jpg

Thanks for your help with this.


0 Likes
Message 4 of 6

jason_lightfootVL7B4
Autodesk
Autodesk

The header doesn't seem to match those of the healthcare Source activities. It should look like this:

/**Custom Code*/
Object current = param(1); 
Object patient = current;
treenode activity = param(2);
Token token = param(3);
int rowNumber = param(4); //The arrival entry row number
int cycle = param(5); //The current cycle through the arrivals table (first iteration cycle = 1)
string labelName = param(6);
treenode processFlow = ownerobject(activity);


I'm not sure why you can't just use the current model time when the token is created:

Math.frac(Model.dateTime.excelTime)*days(1)

gives you the number of time units since the start of the day/midnight.

0 Likes
Message 5 of 6

moehlmann_fe
Enthusiast
Enthusiast

As Jason said, it seems like you are using an "Assign Labels" activity. The rownumber and cycle values (and the correct 'varnode') are only available when the token is first created in the Date Time Source of the Arrivals flow. So you have to assign the label there. They are automatically copied to the patient that the token creates afterwards.

1664263053706.png

0 Likes
Message 6 of 6

jason_lightfootVL7B4
Autodesk
Autodesk

Hi @Tee Hiett, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. 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