Compare dates and view the rest until the expiration date

advertisements
@if (DateTime.Today < item2.VoucherCampaign.ExpiryDate)
{
    <h3>Expires: <span style="color:#FF0000"> Days Remaining</span></h3>
}

This is my mark up right now. I am trying to compare the date of today to the expiry date and than output the days remaining. I have no idea on going about putting the count of days left in my h3 I have there.

My example would be Expires: September 09, 2011 :: 9 Days Remaining.

Maybe there is a different method for DateTime that would help?.

I'm doing my code inside of my .cshtml


You can subtract DateTime values, and the result is a TimeSpan value. You can use the Days property to get the difference in days:

@((item2.VoucherCampaign.ExpiryDate - DateTime.Today).Days)