Calculate Time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klaydze
    New Member
    • Mar 2007
    • 30

    Calculate Time

    hi everyone, i know this is easy to others but i'm going to explode now to this. the scenario is this. i would like to trace where the time is equivalent to 1st Shift, 2nd Shift and 3rd Shift where 1st Shift = 6AM - 2PM, 2nd Shift = 2PM - 10PM and the 3rd Shift = 10PM - 6AM..

    i would like to trace the shift by the time format 12HR not 24HR format. i done this using 24HR but i want to change it to 12HR. The logic i made is this, i will trace either the time is AM or PM then create some condition. some time it gives me a corrent output but others not.

    this is the piece of my code:

    NOTE: CurrentHour is a variable where i get the 2 digit hour and the AMPM is the format of the time wheather it is AM or PM and the Description is a variable where i where the description wheather is is 1st, 2nd, or 3rd shift. in Automation they called it Tag.

    Code:
    IF (CurrentHour >= "06"  AND AMPM == "AM")  AND
        ((CurrentHour >=  "12" AND AMPM == "PM")  AND 
        (CurrentHour <= "02"  AND AMPM == "PM"))THEN    
        Description = "1st Shift";
    
    ELSE
        IF (CurrentHour >= "03" AND AMPM == "PM")  AND 
        (CurrentHour <="10"  AND AMPM == "PM") THEN
        Description = "2nd Shift";
    
    ELSE
        IF (CurrentHour >= "10" AND AMPM == "PM") AND
        (CurrentHour == "12" AND AMPM == "AM") THEN
        Description = "3rd Shift";
    
    ELSE
        Description = "3rd Shift";
    
    ENDIF;
    ENDIF;
    ENDIF;
    by the why the code above is what they code Wonderware a Automation Software but it seems like a VB syntax. Hope you can help me.

    Thank You
    Last edited by debasisdas; Feb 7 '08, 09:49 AM. Reason: added code tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    The semicolon and == says it is not VB 6 code.

    Comment

    • klaydze
      New Member
      • Mar 2007
      • 30

      #3
      Originally posted by debasisdas
      The semicolon and == says it is not VB 6 code.
      helo like what i said the code above is a syntax of a wonderware software which is a Automation software but the logic is the same in vb. i just wan't to hear from you some suggestion for the logic of getting the shift in the given time.

      Thank you.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Rather than trying to deal with string values, convert to an actual time value first. Then it's much more simple.

        Comment

        Working...