Shaitan00 Posted November 22, 2005 Posted November 22, 2005 Given the following code: bool LogsDate (string sLogsDate) { DateTime dtNow = DateTime.Now; DateTime dtLogsDate = DateTime.Parse(sLogsDate); // Do the comapring of dtNow and dtLogsDate and return FALSE if they differ by more then 14 days, return true otherwise } [/Code] So my problem is really simple (as stated in the snipplet of code above) - I need to compare dtNow and dtLogsDate to determine if more or less then X (x=14) days have passed so I can return true or false as required. Any help/hints would be appreciated - thanks, Quote
Wraith Posted November 22, 2005 Posted November 22, 2005 bool LogsDate (string sLogsDate) { DateTime dtNow = DateTime.Now; DateTime dtLogsDate = DateTime.Parse(sLogsDate); [b]TimeSpan datediff = dtNow-dLogsDate; return (datediff.Days>14);[/b] } [/Code] So my problem is really simple (as stated in the snipplet of code above) - I need to compare dtNow and dtLogsDate to determine if more or less then X (x=14) days have passed so I can return true or false as required. Any help/hints would be appreciated - thanks, Your function is badly named and your description of the problem is a little poor. What do you want to know exactly? now>log? now>=log? now<=log? Clarity would help here. The principle you were missing is that the difference between any two DateTime's is a TimeSpan, you can use all sorts of things like Days Minutes Hours from on TimeSpan instances. The documentation is the place to look for this detail. Quote
Shaitan00 Posted November 22, 2005 Author Posted November 22, 2005 Guess your right.... SUBJECT = Determine if 14 days have passed between NOW and the sLogsDate value. Function Name: HasTimeElapsed(string sLogsDate) And I want to compare DAYS.... Now, I see what you mean and that type of thing should work just fine. I'll do some reading on TimeSpan. Thanks, Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.