question

Aditya Prakash avatar image
1 Like"
Aditya Prakash asked Preet commented

How do I obtain current simulation date and time?

How do I obtain current date. Is realtime() the best way to do it?

FlexSim 16.1.0
timesimulation timedaterealtimesimulation date
5 |100000

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

Matt Long avatar image
7 Likes"
Matt Long answered Joshua S commented

There's a new command in FlexSim 2106 called convert(). Convert allows you to convert dates and times from different formats like Excel Date Time, FlexSim Date Time and Model Time. This is especially useful when importing data from Excel that is based upon specific dates and times.

A couple of ways you can use the convert() command is in conjunction with the time() command and getmodelunit()

getmodelunit(CURRENT_TIME) //Returns FS_DATETIME
time() //Returns model time
convert(time(), MODEL_TIME, DATETIME_STR) //Will print out date time based upon the date/time format string, for example 8:00:00 AM Fri 24 Jun 2016

Check out the command documentation for convert() for more information.

· 2
5 |100000

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

Michael avatar image Michael commented ·

Matt - where can I find the command documentation?

0 Likes 0 ·
Joshua S avatar image Joshua S Michael commented ·

@Michael Under the Help Tab click on "FlexScript API Reference" or the "Commands"

1 Like 1 ·
pic1.png (10.2 KiB)
Ben Wilson avatar image
7 Likes"
Ben Wilson answered Preet commented

realtime() will give you the real current date and time, from your computer's clock. This should closely match the time you see on your watch, your cell phone, or the clock on the wall. This is different than the time in your simulation.

If you are looking for the current date in your simulation, this is based on your chosen time unit and start date, both specified when starting a new model.

As you're running your simulation, you can obtain various date and time values for current simulation time from the tree as shown here:


modelunits.png (32.3 KiB)
simtime.gif (221.5 KiB)
· 3
5 |100000

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

Preet avatar image Preet commented ·

Hi @Ben Wilson ! How would I convert realtime(); to DD/MM/YYYY HH:MM:SS timeformat?

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Preet commented ·

Here's a script to print your string to the output console:

string year=realtime(12).substr(21,4);            //  2023
string datestr=realtime(11);                      //  11/13/23
string date=datestr.substr(1,6)+year;             //  11/13/2023
string realtimeString=date+" "+realtime(10);      //  11/13/2023 23:23:10
DateTime dt=DateTime(realtimeString,"%m/%d/%Y %T");
print (dt.toString("%d/%m/%Y %T"));            // 13/11/2023 23:23:10
0 Likes 0 ·
Preet avatar image Preet Jason Lightfoot ♦ commented ·
Thank you @Jason Lightfoot . That worked fine!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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