question

Javier PL avatar image
0 Likes"
Javier PL asked Javier PL edited

Function that returns the number of days of the current month?

Hello there,

I would like to know if there is a way (method) to get the total number of days of the current month. For example, a function that returns 29 if I passed it the current date (today is 24/02/2020).

Just in case some help may show up, I aimed to design a user command which is able to return the number of days off a resource (which in turn has been assigned to a particular schedule) has taken during a defined period of time. As for now, I'm just considering the normal work schedule (weekends off) and calculating the days off between two passed dates. This way I can get the effective time a sequence task has taken to a specific transport to complete some tasks (much easier if using PF with WaitForEvents and Delays, but I'm not considering this possibility right now). The eventual purpose is to subtract this task time from the next processing time, in order not to influence a fixed whole time of both activities altogether. In other words, it's just a matter of transport visualization, which must not have any influence on activities delays.

Hoping I've been clear enough,

Javi

FlexSim 19.0.2
timescheduledown timemonth
5 |100000

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

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Javier PL edited

You could compose a DateTime that is the first day of the next month, then subtract a second (to get the last day of the current month) and get the day:

  1. DateTime currentDate = DateTime.compose(2020, 2, 24);
  2. int numDaysInMonth = DateTime(DateTime.compose(currentDate.year, (currentDate.month % 12) + 1).as(double) - 1.0).day;
  3. return numDaysInMonth;

Here's the same code with each operation on a separate line instead of all on one line:

  1. DateTime currentDate = DateTime.compose(2020, 2, 24);
  2. DateTime nextMonth = DateTime.compose(currentDate.year, (currentDate.month % 12) + 1);
  3. DateTime lastDayOfCurrentMonth = nextMonth - 1.0; // one second earlier
  4. int numDaysInMonth = lastDayOfCurrentMonth.day;
  5. return numDaysInMonth;

You could put this code into a user command to make it easier to read and reuse.

daysinmonth.fsm

  1. DateTime currentDate = DateTime.compose(2020, 2, 24);
  2. return DaysInMonth(currentDate);

daysinmonth.fsm (23.2 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.

Marcello Rosadini avatar image
2 Likes"
Marcello Rosadini answered Javier PL commented

Hi Javi, I am not aware of such a method (probably someone will propose a more elegant solution).

However, you could have a simple 12 row table manually inputing the number of days for each month in the year you are simulating and then use the month property to look up on that?

something like: doublecurrentMonth=Model.dateTime.month

· 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.