Jump to content

Extracting Calendar Attributes from TimeNow Variable


Recommended Posts


I have built a model that requires the use of seasonality data to increase or decrease demand patterns in customer orders. To do this, I have created a data table with one column for months of the year (as a calendar date/time) and another with percentage increase (or decrease) demand. I was attempting to use the TimeNow variable to match the simulation time to the calendar time in the columns (using the 'search' function in an add-on process trigger, a la Search Tables SimBit). Unfortunately, for this to work (conceptually) I would have to fire the process every time step (which is inefficient). And even doing the process this way doesnt seem to be matching TimeNow to a calendar date in my table. Is there a way to extract a calendar attribute (in this case, a month) from the TimeNow variable?


Albert Munoz

Link to comment
Share on other sites


In order to extract date time infortmation from TimeNow, I combine the use of the FromDateTime and Substring functions. For example:

To get the date in a MM/DD/YY format, I use : String.Substring(String.FromDateTime( TimeNow ),1,8)

To get tim information in HH:MM:SS, I use : String.Substring(String.FromDateTime( TimeNow ),12,8)

Happy Modeling,

Link to comment
Share on other sites

Good advice Steve,

One minor correction: Simio returns a date with a 4 digit year, so you would actually have to use:

String.Substring(String.FromDateTime( TimeNow ),1,10) to get the date in a MM/DD/YYYY format

To get months of the year would be (color added to highlight components):

String.ToReal(String.Substring(String.FromDateTime( TimeNow ),1,2))

Of course if you wanted something simple like hour of day, you could take advantage of TimeNow being in hours and use a numeric expression like:

Math.Remainder (TimeNow, 24)

If you want to limit the precision add use of the Math.Floor or Math.Round functions like:

Math.Floor(Math.Remainder (TimeNow, 24 )) to display integer hour or

Math.Round(Math.Remainder (TimeNow, 24 )*100)/100 to display hundredths of hours.

Note that all of these can be used in Status Labels and Floor Labels as in the attached example.IllustrationOfTimeFormats.spfx


You can see more examples if you look at the Floor Labels in the Simio Example named HospitalEmergencyDepartment.

Link to comment
Share on other sites

  • 4 months later...

Update: As of Sprint 65, the software now contains DateTime functions that return a number representing a minute, hour, day, month or year based on a datetime input (such as TimeNow). There are also additional functions that convert a datetime to/from a string and those that let you determine which day of the week, month or year corresponds to a given datetime. See Help for more information on these new functions. Examples of these functions are:

DateTime.Month(datetime) - which will return the month component, expressed as an integer between 1 and 12, for the specified datetime value (if you want the month of the current simulation time, put TimeNow in the parenthesis).

DateTime.DaysInMonth(month, year) - which will return the number of days in the specified month and year. Specify the month as a number ranging from 1 to 12 and the year as a number ranging from 1 to 9999.

DateTime.ToString(datetime) - which will return a formatted datetime string for the specified numeric datetime value. For example, 02/08/2012 00:00:21.

Link to comment
Share on other sites

  • 2 years later...

Hi all,

Thanks to those for showing the building blocks of Date Time conversions. Here is an additional expression.

If you need to import a Time and Date into MySQL the following expression will convert the Simio Date Time format to the MySQL format.


String.Substring(DateTime.ToString(TimeNow), 7, 4) + "-" + String.Substring(DateTime.ToString(TimeNow), 4, 2) + "-" + String.Substring(DateTime.ToString(TimeNow), 1, 2) + " " + String.Substring(String.FromDateTime(TimeNow), 12, 

{See corrected posting below}

Hope it helps.



Link to comment
Share on other sites

Hi all,

Made a mistake. The right code is:


String.Substring(DateTime.ToString(TimeNow), 7, 4) + "-" + String.Substring(DateTime.ToString(TimeNow), 1, 2) + "-" + String.Substring(DateTime.ToString(TimeNow), 4, 2) + " " + String.Substring(String.FromDateTime(TimeNow), 12, 


Antecedently swapped the Date and Months around.


Link to comment
Share on other sites


  • Create New...