C # check age of db Item

I am using C # to send an email with an encrypted link. The encrypted portion of the link contains a timestamp that should be used to check if the link is more than 48 hours old. How can I compare the old time with the current time and find out if the old time was 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 a very reverse way of doing it, and I know hours.CompareTo will have to be adjusted if I stick to comparing ticks. How can I just get a value for the number of hours passed?

+2


source to share


2 answers


(DateTime.Now - data.DTM.Value).TotalHours > 48

      



+4


source


DateTime.Now.Ticks are not hours ... they are ticks ... very small intervals on your computer.

try it



    if ((DateTime.Now - data.DTM).TotalHours > 48) //if link is more than 48 hours old, deny access.

        return View("LinkExpired");
    }

      

+1


source







All Articles