• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

Change label text every 2 weeks

I will explain this best way I can.  I am designing a piece of software for the department I work in. In the department, there are 3 teams, and 3 shifts.  Team A,B,C and the shift times are 0630-1500, 1430-2300, 2230-0700.  We rotate every 2 weeks to another shift.  

Example: 8-24-2014 to 9-06-2014 A team is 1430-2200, B team is 2230-0700, C team is 0630-1500.  
The teams will rotate on 9-07-2014 to 09-20-2014.  So then A team is 2230-0700, B team is 0630-1500, C team is 1430-2200.

This happens every 2 weeks.  I need to make a label that will look at the time and date and know what team is on what shift.  I do not have any code to start with, and I am not asking for code, I am asking for a starting point.  I can not wrap my head around how to even start coding this.  I have made a lot of programs and have never ran into this before.  Any help would be greatly appreciated!!  If I did not make sense or need more of a description please let me know.  Thanks in advance!  I know vb.net fairly well, but do not know c++
  • 3
  • 2
  • 2
2 Solutions
Dan CraciunIT ConsultantCommented:
Store the shifts in an associative array (dictionaries in VB):
week1 = {teamA:"06:30", teamb:"14:30", teamc:"22:30"}
week2 = {teamA:"06:30", teamb:"14:30", teamc:"22:30"}
week3 = {teamA:"22:30", teamb:"06:30", teamc:"14:30"}
and so on.
week6 = {teamA:"14:30", teamb:"22:30", teamc:"06:30"}

Basically you repeat every 6 weeks. Get the week number (calendar.GetWeekOfYear), divide by 6, get the remainder and you'll know what team is on what shift.

russell12Author Commented:
Thank you for the quick response.  This definitely helps, it is pointing me in the right direction!!  The only thing that I an not understanding is lets say we are on week 20.  If you take 20/6 you get 3.3333333.  The array will not match to lets say week "3".  I do have the following code written from the example you gave me:

    Dim myCI As New CultureInfo("en-US")
        Label30.Text = myCI.Calendar.GetWeekOfYear(DateTime.Now, 0, DayOfWeek.Sunday)
        If Label30.Text <= 1 Or Label30.Text >= 2 Then
            Label4.Text = 1
            Exit Sub
        End If
        If Label30.Text <= 3 Or Label30.Text >= 4 Then
            Label4.Text = 2
            Exit Sub
        End If
        If Label30.Text <= 5 Or Label30.Text >= 6 Then
            Label4.Text = 3
            Exit Sub
        End If

Open in new window

I may not be thinking of the math in the proper way, but for example on the next rotation we will be in week 37.  If you take 37/6 you get 6.17.  If you subtract 2 from that you get 4.17.  Then the next rotation happens on week 39.  If you take 39/6-2 you get 4.5.  I sure I am missing something very small.  Thanks again for your help!!
Dan CraciunIT ConsultantCommented:
You need the remainder. 20/6 is 3, remainder 2. This means you're on week 2 (or 3, if you choose to not start from 0).
On week 37, you get remainder 1, which means you're on week 1 again. This keeps repeating:
18 - week 0
19 - week 1
20 - week 2
21 - week 3
22 - week 4
23 - week 5
24 - week 0 again, and so on

In VB I think it's called Mod the operator, so you'll get something like this:
if weekno Mod 6 = 0 then do whatever you want with week 0
if weekno Mod 6 = 1 etc
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Do you work 7 day weeks or 5 day weeks (Mon - Fri), as this will affect what is required on the first day of the week.

If you work a 7 day week then the time prior to 06:30 on day 1 of the week is actually the last shift from the previous week, so you should subtract 6.5 hrs from the local time.

OffsetTime = now.addhours(-6.5)

Also, what happens at the end of the year, some years have 53 weeks, so what you really need to do is work out the number of weeks since a starting date. This is done using DateDiff

NumberOfWeeks = DateDiff(DateInterval.WeekOfYear, BaseDate, OffsetTime)

You can then work out the shift pattern using the Mod function as previously suggested

ShiftPattern = NumberOfWeeks Mod 6

This will return 0 or 1 for pattern 1, 2 or 3 for pattern 2 and 4 or 5 for pattern 3
russell12Author Commented:
I did not even think of that.  You are absolutely correct about this.  Our department works 5 (M-F) days when its not peak season and 6 (M-Sat) days during peak season.  The kicker to all this is the team that works the 2230-0700 comes in on Sunday night at 2230.  The plant considers this as Monday.  I have never worked for a company that did it this way.  Doing the DateDiff formula would actually compensate for the leap years right?  I would use the start date 09-07-2014.  Thanks to the both of you for helping me through this.  I am working on trying to get the code together and written up.  Also one question for you and this is probably a common sense question, but what is the "BaseDate"?  That's the only part I am stuck on.  I tried DateTime.Now but I am getting a 0.  The code I tried is:

        Dim numberofweeks As Integer
        Dim offsettime As DateTime
        OffsetTime = Now.AddHours(-6.5)
        numberofweeks = DateDiff(DateInterval.WeekOfYear, DateTime.Now, offsettime)

Open in new window

Dan Craciun:

Thank you for all your help!!  I am pulling the correct week number with your solution!!  I appreciate you not just giving me the answer and working with me.  That's how I learn!!!
Thanks again!!
Base date would be the stardate. So this would be whatever you want, but would need to be the Monday of a week 1. So if next Monday was the start of week 1, base date would be

BaseDate = New Date(2014,9,8,0,0,0)

It is not Now, as otherwise you would always be in week 1

Rather than deducting 6.5 you should add 1.5. This will mean that 22:30 on the Sunday night is calculated as 00:00, and everything else is calculated from there.
russell12Author Commented:
Dan Craciun :
Thank you for all your help!!  You pointed me in the right direction and I am thankful for this!!

ChloesDad :
Thank you for joining in and adding your knowledge with this.  You helped a lot also!!

I wish I could give you both 500 points each.  Both answers are the best answer!  Thanks a lot!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now