Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Subtracting minutes from ToTime Integer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Subtracting minutes from ToTime Integer

    Hi,

    I have sometime like this in my code:

    Code:
    int startTime = 93000
    int endTime = 155000
    
    if (ToTime(Time[0])<startTime || ToTime(Time[0])>endTime - [minutes])
       stopEntry = true;
    The [minutes] part is where I'm having issues with. How can code it so that I can specify the number of minutes to subtract from endTime? If I'd like it to end 50 minutes before endTime, simply coding

    Code:
    endTime - 5000
    does not really work in all situations (i.e. if endTime was 160000, then 160000 - 5000 would be 155000, or 3:50pm instead of 3:10pm).

    Any help would be much appreciated. Thanks.

    -Nick

    #2
    Update:

    This is what I managed to knock out:


    Code:
    myDateTime = DateTime.ParseExact(endTime.ToString(), "HHmmss", CultureInfo.InvariantCulture);
    myDateTime = myDateTime.AddMinutes(-20);
    				
    string format = myDateTime.ToString("HHmmss");
    int endTimeFinal = Int32.Parse(format);
    It's brutal. It's ugly. It's probably a lot longer than it needs to be. But it works.

    Any suggestions on how I can "elegant-ize" it?

    Thanks!

    Comment


      #3
      Update #2:

      Ahh, the wonders of stackoverflow.

      Replaced:

      Code:
      string format = myDateTime.ToString("HHmmss");
      int endTimeFinal = Int32.Parse(format);
      with

      Code:
      int endTimeFinal = int.Parse(myDateTime.ToString("HHmmss"));
      So far, so good!

      Comment


        #4
        Timespan?

        Comment


          #5
          Originally posted by nicbizz View Post
          Update:

          This is what I managed to knock out:


          Code:
          myDateTime = DateTime.ParseExact(endTime.ToString(), "HHmmss", CultureInfo.InvariantCulture);
          myDateTime = myDateTime.AddMinutes(-20);
          				
          string format = myDateTime.ToString("HHmmss");
          int endTimeFinal = Int32.Parse(format);
          It's brutal. It's ugly. It's probably a lot longer than it needs to be. But it works.

          Any suggestions on how I can "elegant-ize" it?

          Thanks!
          You evidently know how to code with DataTime objects. Why not just use them directly? After all, Time[n] objects are already DateTime objects.

          Not to put a fine point on it, but that is far more elegant than all this trying to pretend "times" are integer objects.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          333 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X