Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to compare time?

How to compare time?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheeken2u
    wrote on last edited by
    #1

    if i have two time variables: a = 08:32 ( 08 is hours; 32 is minutes) b = 13:54 how to compare this time format? ( the time output should be b longer than a )

    Best regards, Chee ken

    G J C 3 Replies Last reply
    0
    • C cheeken2u

      if i have two time variables: a = 08:32 ( 08 is hours; 32 is minutes) b = 13:54 how to compare this time format? ( the time output should be b longer than a )

      Best regards, Chee ken

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      If you use TimeSpan structures, you can compare them and do calculations on them. Example: TimeSpan a = new TimeSpan(8, 32, 0); TimeSpan b = new TimeSpan(13, 54, 0); if (a > b) Console.WriteLine("Time a is longer."); if (b > a) Console.WriteLine("Time b is longer."); if (a == b) Console.WriteLine("They are equal."); Console.WriteLine("Comparison: " + ToString(TimeSpan.Compare(a, b))); Console.WriteLine("Differece in minutes: " + ToString((b - a).TotalMinutes));

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • C cheeken2u

        if i have two time variables: a = 08:32 ( 08 is hours; 32 is minutes) b = 13:54 how to compare this time format? ( the time output should be b longer than a )

        Best regards, Chee ken

        J Offline
        J Offline
        John Petersen
        wrote on last edited by
        #3

        You can also compare to DateTime values and the result is a TimeSpan DateTime date1 = DateTime.Parse("2006-06-01 08:32"); DateTime date2 = DateTime.Parse("2006-06-01 13:54"); TimeSpan span1 = date2 - date1; -- modified at 9:20 Saturday 21st October, 2006

        Kind Regards, John Petersen

        1 Reply Last reply
        0
        • C cheeken2u

          if i have two time variables: a = 08:32 ( 08 is hours; 32 is minutes) b = 13:54 how to compare this time format? ( the time output should be b longer than a )

          Best regards, Chee ken

          C Offline
          C Offline
          cheeken2u
          wrote on last edited by
          #4

          I solve this problem already with your help ,thanks Guffa and John Petersen.. :)

          Best regards, Chee ken

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups