Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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,

Posted

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.

Posted

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,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...