DateTime

Description

A class containing functions for getting and manipulating dates and times.

This DateTime class allows you to create and manipulate dates and times that are stored as FlexSim time. FlexSim time is defined as the number of seconds since January 1st, 1601. The specified Model Time Units does not affect FlexSim time. It is always in seconds.

Model Settings

When you start a new model, you can specify the start date and time of the model. That can later be changed through the Model Settings page. On that page you can also specify the date and time display format. These formats can be used when displaying a DateTime as a string or for creating a DateTime.

Excel Import/Export

When you import dates and times from an Excel document, you can do so as either strings or as numbers which are in Excel time. This DateTime class can be used to convert those strings or Excel time into FlexSim time. For exporting, you can write formatted dates and/or times to a global table using the DateTime.toString method.

Dashboard Charts

Dashboard charts like the Time Plot can use FlexSim time to display the dates and times along the X or Y axis. This can be done by recording DateTimes in a Statistics Collector.

Properties

day The day of the month
dayOfWeek The day of the week
hour The hour of the day
millisecond The millisecond of the second.
minute The minute of the hour.
month The month of the year
second The second of the minute.
totalDays The number of days since January 1st, 1601.
totalHours The number of hours since January 1st, 1601.
totalMilliseconds The number of milliseconds since January 1st, 1601.
totalMinutes The number of minutes since January 1st, 1601.
totalSeconds The number of seconds since January 1st, 1601.
value The value of the date and time in FlexSim time.
year The year

Methods

toString Converts the DateTime into a human readable string.

Constructor

DateTime Constructs a DateTime.

Static Methods

days Constructs a new DateTime from the number of days.
fromExcelTime Converts Excel time into FlexSim time.
hours Constructs a new DateTime from the number of hours.
milliseconds Constructs a new DateTime from the number of milliseconds.
minutes Constructs a new DateTime from the number of minutes.
seconds Constructs a new DateTime from the number of seconds.

Operators

- Substracts one DateTime from another.
!= Compares two DateTimes.
+ Adds two DateTimes together.
< Compares two DateTimes.
<= Compares two DateTimes.
== Compares two DateTimes.
> Compares two DateTimes.
>= Compares two DateTimes.

Details

Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.day

readonly double day

Description

The day of the month

Value ranges from 1 to 31. double currentDay = Model.dateTime.day;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.dayOfWeek

readonly double dayOfWeek

Description

The day of the week

Value ranges from 1 to 7 with 1 being Sunday. double currentDayOfWeek = Model.dateTime.dayOfWeek;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.hour

readonly double hour

Description

The hour of the day

Value ranges from 0 to 23 with the 0 hour being from 12:00:00AM to 12:59:59AM. double currentHour = Model.dateTime.hour;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.millisecond

readonly double millisecond

Description

The millisecond of the second.

Value ranges from 0 to 999. double currentMillisecond = Model.dateTime.millisecond;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.minute

readonly double minute

Description

The minute of the hour.

Value ranges from 0 to 59. double currentMinute = Model.dateTime.minute;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.month

readonly double month

Description

The month of the year

Value ranges from 1 to 12. double currentMonth = Model.dateTime.month;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.second

readonly double second

Description

The second of the minute.

Value ranges from 0 to 59. double currentSecond = Model.dateTime.second;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.totalDays

readonly double totalDays

Description

The number of days since January 1st, 1601.

This will return a floating point number where the fraction represents the time into the current day. double totalDays = Model.dateTime.totalDays;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.totalHours

readonly double totalHours

Description

The number of hours since January 1st, 1601.

This will return a floating point number where the fraction represents the time into the current hour. double totalHours = Model.dateTime.totalHours;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.totalMilliseconds

readonly double totalMilliseconds

Description

The number of milliseconds since January 1st, 1601.

This will return a floating point number where the fraction represents the time into the current millisecond. double totalMilliseconds = Model.dateTime.totalMilliseconds;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.totalMinutes

readonly double totalMinutes

Description

The number of minutes since January 1st, 1601.

This will return a floating point number where the fraction represents the time into the current minute. double totalMinutes = Model.dateTime.totalMinutes;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.totalSeconds

readonly double totalSeconds

Description

The number of seconds since January 1st, 1601.

This is equivalent to DateTime.value or putting the DateTime into a double. double totalSeconds = Model.dateTime.totalSeconds;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.value

readonly double value

Description

The value of the date and time in FlexSim time.

This property is equivalent to DateTime.totalSeconds or putting a DateTime into a double.

double currentTime = Model.dateTime.value;
double currentTime = Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.year

readonly double year

Description

The year

double currentYear = Model.dateTime.year;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.toString()

string toString( string format = )

Parameters

format If format is NULL, the default windows date/time format will be used.

Description

Converts the DateTime into a human readable string.

This method uses the windows settings for formatting. When using a custom format, the following formatting options are available:
SpecifierExplanationExample
%%A % character%
%nNew line character
%tHorizontal tab character
Year
%YThe four digit year2017
%yThe last two digits of the year17
%CThe first two digits of the year20
Month
%bThe abbreviated month nameOct
%BThe full month nameOctober
%mThe month as a number (1 - 12)10
Week
%UThe week of the year as a number with Sunday being the first day of the week (00 - 53)15
%WThe week of the year as a number with Monday being the first day of the week (00 - 53)15
Days of the year/month
%jThe day of the year as a three digit number (001 - 366)045
%dThe day of the month as a two digit number (01 - 31)05
%eThe day of the month as a single digit number (1 - 31)5
Day of the week
%aThe abbreviated weekday nameFri
%AThe full weekday nameFriday
%wThe weekday as a number where Sunday is 0 (0 - 6)3
Hour, minute, second
%HThe hour as a two digit number, 24 hour clock (00 - 23)08
%IThe hour as a two digit number, 12 hour clock (01 - 12)08
%MThe minute as a two digit number (00 - 59)30
%SThe second as a two digit number (00 - 60)25
Other
%cThe standard date and time (windows default setting)09/24/17 08:00:00
%xThe standard date (windows default setting)09/24/17
%XThe standard time (windows default setting)08:00:00
%DEquivalent to %m/%d/%y09/24/17
%FEquivalent to %Y-%m-%d2017-09-24
%rThe 12-hour clock time (based on windows setting)08:00:00
%REquivalent to %H:%M08:00
%TEquivalent to %H:%M:%S08:00:00
%pAM or PM (based on windows setting)AM
%zThe offset from UTC time-0600
%ZThe time zone name or abbreviationMountain Daylight Time

string currentDateTime = Model.dateTime.toString();
string currentDateTime = Model.dateTime.toString("%H:%M:%S");
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime Constructor

DateTime( double time )
DateTime( int days , int hours , int minutes = 0 , int seconds = 0 )

Parameters

time The number of seconds since January 1st, 1601.
days The number of days to add to the final DateTime
hours The number of hours (usually less than 24) to add to the final DateTime
minutes The number of minutes (usually less than 60) to add to the final DateTime
seconds The number of seconds (usually less than 60) to add to the final DateTime

Description

Constructs a DateTime.

The time can be treated as a duration if you add two DateTimes together. For example,

DateTime futureDate = Model.dateTime + DateTime(340); //Add 340 seconds to the current model time
			

DateTime theDate = DateTime(3600);
			

The second constructor can be used to create a DateTime that is rounded down to the nearset important marker. For example, if the current model time is between 8:00 and 9:00 on a particular day, you could use the following code to create a date time that represents 8:00 on that same day:

DateTime roundedToHour = DateTime(Model.dateTime.totalDays, Model.dateTime.totalHours);
			
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.days()

static DateTime days( double days )

Description

Constructs a new DateTime from the number of days.

DateTime oneDay = DateTime.days(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.fromExcelTime()

static DateTime fromExcelTime( double excelTime )

Description

Converts Excel time into FlexSim time.

When performing an Excel Import, the Data Distinction can be set to Values Only. This will cause cells that store dates to be imported into FlexSim as numbers that are in Excel time. This method will convert that Excel time into FlexSim time. DateTime dateTime = DateTime.fromExcelTime(excelTime);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.hours()

static DateTime hours( double hours )

Description

Constructs a new DateTime from the number of hours.

DateTime oneHour = DateTime.hours(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.milliseconds()

static DateTime milliseconds( double milliseconds )

Description

Constructs a new DateTime from the number of milliseconds.

DateTime oneMillisecond = DateTime.milliseconds(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.minutes()

static DateTime minutes( double minutes )

Description

Constructs a new DateTime from the number of minutes.

DateTime oneMinute = DateTime.minutes(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.seconds()

static DateTime seconds( double seconds )

Description

Constructs a new DateTime from the number of seconds.

DateTime oneSecond = DateTime.seconds(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator -

DateTime operator -( DateTime other )

Parameters

other The DateTime to subtract from this DateTime.

Returns

DateTime The resulting DateTime.

Description

Substracts one DateTime from another.


DateTime subTwoDates = Model.dateTime - dateTime;
DateTime subOneDay = Model.dateTime - DateTime.days(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator !=

int operator !=( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if the two DateTimes are different, false otherwise.

Description

Compares two DateTimes.

int differentDates = dateTime != Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator +

DateTime operator +( DateTime other )

Parameters

other The DateTime to add this one to.

Returns

DateTime The resulting DateTime.

Description

Adds two DateTimes together.


DateTime addTwoDates = Model.dateTime + dateTime;
DateTime addOneDay = Model.dateTime + DateTime.days(1);
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator <

int operator <( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if this DateTime is less than other, false otherwise.

Description

Compares two DateTimes.

int pastDate = dateTime < Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator <=

int operator <=( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if this DateTime is less than or equal to other, false otherwise.

Description

Compares two DateTimes.

int pastDate = dateTime <= Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator ==

int operator ==( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if the two DateTimes are exactly the same, false otherwise.

Description

Compares two DateTimes.

int sameDate = dateTime == Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator >

int operator >( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if this DateTime is greater than other, false otherwise.

Description

Compares two DateTimes.

int futureDate = dateTime > Model.dateTime;
Do no remove, this fixes the anchor on doc.flexsim.com

DateTime.operator >=

int operator >=( DateTime other )

Parameters

other The DateTime to compare to this DateTime.

Returns

int True if this DateTime is greater than or equal to other, false otherwise.

Description

Compares two DateTimes.

int futureDate = dateTime >= Model.dateTime;