Comparing Dates to see if more then 14 days have passed [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Location
Hell
Given the following code:
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        
}

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,
 

Wraith

Regular
Joined
Mar 23, 2004
Shaitan00 said:
Code:
bool LogsDate (string sLogsDate)
{
	DateTime dtNow = DateTime.Now;
	DateTime dtLogsDate = DateTime.Parse(sLogsDate);

	[B]TimeSpan datediff = dtNow-dLogsDate;
	return (datediff.Days>14);[/B]
}

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.
 

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Location
Hell
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,
 
Top Bottom