aqeel
aqeel

Reputation: 1

DATETIME Error(Finding total days)

I want to find number of days:

int totalDays = (from d in db.RentalDvds.Where(d => d.ReturnedDate.HasValue && d.RentedDate.HasValue)
select (d.ReturnedDate - d.RentedDate).Days).FirstOrDefault();

but it gives the error

Error 1 'System.Nullable' does not contain a definition for 'Days' and no extension method 'Days' accepting a first argument of type 'System.Nullable' could be found (are you missing a using directive or an assembly reference?)

Upvotes: 0

Views: 250

Answers (1)

undefined
undefined

Reputation: 34269

int totalDays = (
from d in db.RentalDvds
where d.ReturnedDate.HasValue &&  d.RentedDate.HasValue
select (d.ReturnedDate.Value - d.RentedDate.Value).Days).FirstOrDefault();

you need .Value if the type is nullable

Upvotes: 2

Related Questions