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
  1. Home
  2. Web Development
  3. ASP.NET
  4. compare Date and Time

compare Date and Time

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
6 Posts 4 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.
  • S Offline
    S Offline
    Sarfaraj Ahmed
    wrote on last edited by
    #1

    Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj

    Sarfarj Ahmed

    A A 2 Replies Last reply
    0
    • S Sarfaraj Ahmed

      Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj

      Sarfarj Ahmed

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      If string to DateTime conversion is yur problem then u can use, Convert.ToDateTime("10/02/2009 03:37:25") to make a DateTime object of your string. Alternately, DateTime.Parse. For comparing, http://www.codeproject.com/script/Forums/View.aspx?fid=12076&select=2917783&fr=1#xx2917783xx[^]

      S 1 Reply Last reply
      0
      • A ABitSmart

        If string to DateTime conversion is yur problem then u can use, Convert.ToDateTime("10/02/2009 03:37:25") to make a DateTime object of your string. Alternately, DateTime.Parse. For comparing, http://www.codeproject.com/script/Forums/View.aspx?fid=12076&select=2917783&fr=1#xx2917783xx[^]

        S Offline
        S Offline
        Sarfaraj Ahmed
        wrote on last edited by
        #3

        Actualy I want to calculate wheather customer date and time (input from customer) is 8 hours more than system date and time or not. Anyway, Thank you very much for replying

        Sarfarj Ahmed

        1 Reply Last reply
        0
        • S Sarfaraj Ahmed

          Hello Everybody I want to compare date and time from two diffrent object Example: lblSystemDateTime = 10/02/2009 03:37:25 lblSelctedDateTime = 10/02/2009 14:30:00 I want to check wheather SelectedDateTime is 12 hours more than SystemDateTime How can I check it. Thanks Sarfaraj

          Sarfarj Ahmed

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4
                  DateTime Dt= DateTime.Parse("10/02/2009 03:37:25");
                  DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00");
                  TimeSpan t = Dt.Subtract(Dt2);
                  MessageBox.Show(t.TotalHours.ToString());
          

          Now From Time Span you can get the time Difference ;)

          cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net

          S N 2 Replies Last reply
          0
          • A Abhijit Jana
                    DateTime Dt= DateTime.Parse("10/02/2009 03:37:25");
                    DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00");
                    TimeSpan t = Dt.Subtract(Dt2);
                    MessageBox.Show(t.TotalHours.ToString());
            

            Now From Time Span you can get the time Difference ;)

            cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net

            S Offline
            S Offline
            Sarfaraj Ahmed
            wrote on last edited by
            #5

            Dear Abhijit Jana Thanks you very much. You are a STAR Thanks Sarfaraj

            Sarfarj Ahmed

            1 Reply Last reply
            0
            • A Abhijit Jana
                      DateTime Dt= DateTime.Parse("10/02/2009 03:37:25");
                      DateTime Dt2 = DateTime.Parse("10/02/2009 14:30:00");
                      TimeSpan t = Dt.Subtract(Dt2);
                      MessageBox.Show(t.TotalHours.ToString());
              

              Now From Time Span you can get the time Difference ;)

              cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              It looks like the date OP is talking about is in dd/mm/yyyy format. If yes, your code will fail. It will take 02 as date and 10 as month. You need to use DateTime.ParseExact with an invariant culture and required format. :)

              Navaneeth How to use google | Ask smart questions

              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