Datetime comparison
-
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.....
-
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.....
-
Use
Subtract
method in theDateTime
class.It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
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....
-
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....
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.
-
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.
Im not getting it...can u please write code for timespan value for subtracting 5...
-
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.....
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