Get data from database compare by datetime or by only date using linq

1. Compare by datetime

public List<tblName> getByDateTime(DateTime dateTime)
{
   return objEntity.tblName.Where(p => p.publish_time <= dateTime).ToList();
}

Call above function

List<tblName> myTbl = getByDateTime(DateTime.Now);

 

2. Compare by date

[sociallocker]

public List<tblName> getByDate(DateTime dateTime)
{
   return objEntity.tblName.Where(p =>    p.publish_time.Year <= dateTime.Year && p.publish_time.Month <= dateTime.Month && p.publish_time.Day <= dateTime.Day ).ToList();
}

[/sociallocker]

Call above function

List<tblName> myTbl = getByDate(DateTime.Now);

 

Leave a comment

Your email address will not be published. Required fields are marked *