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. Datetime comparison

Datetime comparison

Scheduled Pinned Locked Moved ASP.NET
databasecssdata-structures
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.
  • G Offline
    G Offline
    greendragons
    wrote on last edited by
    #1

    I want to check a datetime value saved in db...and only accept those values which are just lagging 5 seconds with current datetime value....i tried with compare and subtract but not getting the point.... <code> string dt = DateTime.Now.ToShortDateString(); \\current datetime value.                   DateTime dt1 = Convert.ToDateTime(dt);                                     string dtime = dr1[0].ToString(); \\datetime value from database.                   DateTime ddt = new DateTime();                   ddt = Convert.ToDateTime(dtime); </code> in my next step i want to check whether ddt value lags 5 or less seconds than dt1(which is current datetime value of system) then save those values to an string array.....

    D G 2 Replies Last reply
    0
    • G greendragons

      I want to check a datetime value saved in db...and only accept those values which are just lagging 5 seconds with current datetime value....i tried with compare and subtract but not getting the point.... <code> string dt = DateTime.Now.ToShortDateString(); \\current datetime value.                   DateTime dt1 = Convert.ToDateTime(dt);                                     string dtime = dr1[0].ToString(); \\datetime value from database.                   DateTime ddt = new DateTime();                   ddt = Convert.ToDateTime(dtime); </code> in my next step i want to check whether ddt value lags 5 or less seconds than dt1(which is current datetime value of system) then save those values to an string array.....

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Use Subtract method in the DateTime class.

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      G 1 Reply Last reply
      0
      • D dan sh

        Use Subtract method in the DateTime class.

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        G Offline
        G Offline
        greendragons
        wrote on last edited by
        #3

        i did but im not quite sure with timespan values that im getting.... what i did timespan ts = dt1subtract[ddt]; now after this how to put condition of 5sec on timespan value....

        C 1 Reply Last reply
        0
        • G greendragons

          i did but im not quite sure with timespan values that im getting.... what i did timespan ts = dt1subtract[ddt]; now after this how to put condition of 5sec on timespan value....

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Perhaps if you had any idea what you were doing, you'd put a . after the timespan and notice that amongst it's properties is one that gives you the time in seconds.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          G 1 Reply Last reply
          0
          • C Christian Graus

            Perhaps if you had any idea what you were doing, you'd put a . after the timespan and notice that amongst it's properties is one that gives you the time in seconds.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            G Offline
            G Offline
            greendragons
            wrote on last edited by
            #5

            Im not getting it...can u please write code for timespan value for subtracting 5...

            1 Reply Last reply
            0
            • G greendragons

              I want to check a datetime value saved in db...and only accept those values which are just lagging 5 seconds with current datetime value....i tried with compare and subtract but not getting the point.... <code> string dt = DateTime.Now.ToShortDateString(); \\current datetime value.                   DateTime dt1 = Convert.ToDateTime(dt);                                     string dtime = dr1[0].ToString(); \\datetime value from database.                   DateTime ddt = new DateTime();                   ddt = Convert.ToDateTime(dtime); </code> in my next step i want to check whether ddt value lags 5 or less seconds than dt1(which is current datetime value of system) then save those values to an string array.....

              G Offline
              G Offline
              GSingh Developer
              wrote on last edited by
              #6

              try this.. DateTime dt1 = database_date; DateTime dt2 = DateTime.Now; TimeSpan t2 = dt1 - dt2; if((t2.Seconds)<=0)//according to ur condition... {} thnx & regards, Gurinder Singh Web Developer

              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