question

Nicolas Mbz avatar image
0 Likes"
Nicolas Mbz asked Nicolas Mbz commented

How to get the number of week from a date ?

In global table, I have dates. like : "07.01.2019 08:22". I would like to get the number of the week.

In Excel, there is un function "=NO.SEMAINE.ISO()" which give the good answer.

1666795067075.png

Is there a way in Flexsim to get the same result ?

Or another way to get the number of the week ?

Thanks in advance

FlexSim 22.2.1
datanumofweek
1666795067075.png (4.9 KiB)
5 |100000

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

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Nicolas Mbz commented

Not directly, as far as I know. There sadly is no direct method to get the week in the Datetime class. You can still use the remaining methods to calculate the week though.

string date = "01.01.2021 08:22";
// Construct datetime from string
DateTime dateTime = DateTime(date, "%d.%m.%Y %H:%M");
int weeks = 0;
int curYear = dateTime.year;
// Find previous monday
while(dateTime.dayOfWeek != 2)
{
    dateTime -= DateTime(86400);
}
// Check if year changed
if(dateTime.year != curYear)
{
    if(dateTime.day > 28)
    {
        // Is first calendar week
        return 1;
    }
    // Is part of last year's last week
    curYear = dateTime.year;
}
// Go to start of year
while(dateTime.year == curYear)
{
    dateTime -= DateTime(604800);
    weeks++;
}
// Check if week belongs to current or last year
if(dateTime.day > 28)
{
    weeks++;
}
return weeks;
· 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.

Nicolas Mbz avatar image Nicolas Mbz commented ·
Seriously, it works ! thanks a lot !


I think this commande must be proposed to the dev. @Jordan Johnson
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.