Entity framework 4 EF4使用Linq我如何才能找到以天为单位的日期差异
我需要检查给定日期和当前日期之间的差异是否小于365天 我试过这样的东西Entity framework 4 EF4使用Linq我如何才能找到以天为单位的日期差异,entity-framework-4,linq-to-entities,Entity Framework 4,Linq To Entities,我需要检查给定日期和当前日期之间的差异是否小于365天 我试过这样的东西 System.TimeSpan diff = DateTime.UtcNow.Subtract((DateTime)customer.LastValidationDate); result = (diff.Days < 1); System.TimeSpan diff=DateTime.UtcNow.Subtract((DateTime)customer.LastValidationDate); 结果=(差异天数
System.TimeSpan diff = DateTime.UtcNow.Subtract((DateTime)customer.LastValidationDate);
result = (diff.Days < 1);
System.TimeSpan diff=DateTime.UtcNow.Subtract((DateTime)customer.LastValidationDate);
结果=(差异天数<1);
这似乎不正确的工作为数不多的日期
我需要实现:
如果给定日期和当前日期之差小于或等于1年(365天),则返回true
否则返回false。请尝试在中找到此选项
public static int MonthDifference(this DateTime lValue, DateTime rValue)
{
return (lValue.Month - rValue.Month) + 12 * (lValue.Year - rValue.Year);
}