C# check age of db Item

Posted by Jacob Huggart on Stack Overflow See other posts from Stack Overflow or by Jacob Huggart
Published on 2010-04-09T16:36:47Z Indexed on 2010/04/09 16:43 UTC
Read the original article Hit count: 389

Filed under:
|
|

Hello All,

I am using C# to send an email with an encrypted link. The encrypted portion of the link contains a time stamp that needs to be used to verify if the link is more than 48 hours old. How do I compare an old time to the current time and find out if the old time is more than 48 hours ago?

This is what I have now:

var hours = DateTime.Now.Ticks - data.DTM.Value.Ticks; //data.DTM = stored time stamp

        if (hours.CompareTo(48) > 1) //if link is more than 48 hours old, deny access.

            return View("LinkExpired");
        }

Comparing ticks seems like it's a very backwards way to do it and I know that the hours.CompareTo would have to be adjusted if I stick with comparing ticks. How can I just get a value for the number of hours that have passed?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc