Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
[ FlexSim 16.1.0 ]
How do I obtain current date. Is realtime() the best way to do it?
Solved! Go to Solution.
[ FlexSim 16.1.0 ]
How do I obtain current date. Is realtime() the best way to do it?
Solved! Go to Solution.
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:
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.
Matt - where can I find the command documentation?
Hi @Ben Wilson ! How would I convert realtime(); to DD/MM/YYYY HH:MM:SS timeformat?
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