question

Malcolm L3 avatar image
0 Likes"
Malcolm L3 asked Jason Lightfoot edited

How do I convert 24 hours time to seconds?

Hi all,


I am able to make use of the "Advance" Mode in Date-Time schedule to implement my model to start at a particular time with it being able to reference to global table with "Number" data type. However, I face issue with converting the 24 hours time e.g (16:00:00) into my model unit time which is in seconds. Thus, I would need help in converting 16:00:00 time into seconds which is (16 x 60 x 60 + 0 x 60 + 0 ), May I know if there is any inbuilt function to convert the referenced value of 16:00:00 (I believe it's a string type) into seconds ( this is base model unit I believe).

FlexSim 20.2.0
flexsim 20.2.0software
1614173745918.png (258.9 KiB)
1614173763431.png (431.5 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 @Malcolm L3, was jason.lightfoot's answer helpful? If so, please click the red "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 0 ·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

UPDATE: this is easiest :

double time = DateTime("16:00:00","%T");  //assigns the time in model time units


If you're importing from Excel you should be able to preserve the numeric value and then convert from Exceltime using the DateTime class.

You control the base model unit when you start FlexSim with the option to select units, or set the default units in Global Preferences under Environment:

You can concatenate the two strings for date and time in your model and convert to a DateTime and then get the hour using:

DateTime dt=DateTime("09/02/2021 16:00:00","%d/%m/%Y %H:%M:%S");
return hours(dt.hour);

But I'm not sure what you're trying to do - if you want to know how far off in the simulation a date is then just subtract one date time from the other.

DateTime dt=DateTime("09/02/2021 16:00:00","%d/%m/%Y %H:%M:%S");
return dt-Model.dateTime;



1614174044889.png (14.4 KiB)
· 7
5 |100000

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

Malcolm L3 avatar image Malcolm L3 commented ·

Hi @jason.lightfoot,

Update: I am able to convert the whole string of 23:30:10 into seconds with the below code.

DateTime dt=DateTime("09/02/2021 23:30:10","%d/%m/%Y %H:%M:%S");

return hours(dt.hour)+ minutes(dt.minute)+ dt.second;

However I need to take reference to my global table where one of the column consist of 24 hours-time. With the above code, it's a constructor take thats in string type, and if I replace 23:30:10 with my script (Table("Pcbquantity")[2][4]), the code doesn't work anymore. May I know how to cater it to my condition?

0 Likes 0 ·
1614516256845.png (63.3 KiB)
Joerg Vogel avatar image Joerg Vogel Malcolm L3 commented ·

Hi @Malcolm L3, Jason has given you a link to the date time class. There you find all can do with a date time data value. I know that you don‘t want to calculate with the date part of the value, but this is currently the structure of the date time value. Maybe the developer will decide in the future to compose the date time class as an interface from two new classes like time and date. But today you have only the date time class. But if you like, you can still create a list or table of 57600 entries to translate a string value into number value just by table look up.

0 Likes 0 ·
Malcolm L3 avatar image Malcolm L3 Joerg Vogel commented ·

Hi @Jörg Vogel,

I get that I am given the date time class, may I know what modification do I have to change to the above code snippet in my replies so that the referencing can work?

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Malcolm L3 commented ·
FlexSim time is defined as the number of seconds since January 1st, 1601

Maybe you are able to get the seconds from a day if you compute them with a string of “January 1st, 1601”. And maybe you are able to get the seconds of your simulation runtime from Model.time. And maybe you are able to get the seconds of any current date day to the time 00:00:01 of every day.

0 Likes 0 ·
Malcolm L3 avatar image Malcolm L3 Joerg Vogel commented ·

I don't see how your answer is link to the part on taking reference of the time data on my global table. I'm very lost and confuse


I'm not sure if you understand what I want to do after all I have said. Jason code is already working for me. I just need to know how to replace the 23:30:10 string with the data in my global table. As u can see from the picture above I cannot just simply reference since it's of string type. The system will just read Table("Pcbquantity")... as a string and not a reference to the data. I just want to be able to reference the data instead of manually typing in 23:30:10 or a new 24 hours time each time I import the 24 hours time data from my data base. May I know how to resolve this issue?

0 Likes 0 ·
Show more comments
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

January 1st 1601 12:34:56 as date time will return in seconds the day time 12:34:56

Please compute the time in seconds of a date day not to the current date instead to the january 1st 1601.

There are the date time FlexSim counts in seconds January 1st, 1601; the model runtime start date in Main Menu in Model settings > it is the current date you run a model at 8 o’clock AM; the runtime in seconds from the start date time of your model by Model.time.

There are properties in Model and DateTime class, which you can use as constants to get fix time values to compute the elapsed times in seconds. The DateTime class is only a translator to visualize the time in seconds from January 1st, 1601 as strings and convert strings to seconds elapsed since January 1st, 1601.

The model run start time is only an offset to the January 1st, 1601 00:00:00.



5 |100000

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