I have a table which has DateTime fields as below:
class ItemSales
{
[PrimaryKey, AutoIncrement]
public int SpId { get; set; }
public string CompanyName { get; set; }
public string ItemNo { get; set; }
public DateTime StartDate { get; set; }
public decimal UnitPrice { get; set; }
public decimal MinimumQuantity { get; set; }
public DateTime EndDate { get; set; }
public decimal Cost { get; set; }
public DateTime InsertDate { get; set; }
---- others
}
---
others
The problem:
How to query where I need to check if the pass-in string date strCurrentDate (DateTime.Now) is between StartDate and EndDate which are in the table?
If I pass in the current date as yyyy-mm-dd and I have the following function:
--- Update
error Message:
Operator '>' cannot be applied to operands of type 'string' and 'System.DateTime'
private async void GetActualPrice(string Cpy, string No, string strCurrentDate,string strSelectedUoM)
{
var db = new SQLiteAsyncConnection(dbPath);
var Items = await db.Table < ItemSales >().Where(x => x.CompanyName == Cpy && x.ItemNo == No && strCurrentDate > x.StarDate && strCurrentDate < x.EndDate).ToListAsync();
foreach (var _line in Items)
{
}
}
No need to convert the Start and End Date into string ???
"'" + strCurrentDate + "'" + " BETWEEN StartDate And EndDate");