Comparing dates in Entity SQL

What is the correct eSQL syntax to compare dates?

The equivalent LINQ-to-Entities expression would look something like this:

var lastYearsShipments = from p in MyDataServiceContext.Products
                         where p.ShipDate.Value.Year == DateTime.Now.Year - 1
                         select p;

Answers


They say it's acceptable to answer your own question, so here goes ...

var predicate = string.Format(
    "Year(it.ShipDate) == Year(cast('{0}' as System.DateTime)) -1",
    System.DateTime.Now);

var lastYearsShipments = 
    myQuery.Products.Where(predicate); // myQuery is type ObjectQuery<T>

See also: msdn documentation


string datetimeFormatter = "yyyy-MM-dd HH:mm";

var predicate = string.Format("Year(it.ShipDate) == Year(DATETIME'{0}')) -1", System.DateTime.Now.ToString(datetimeFormatter)); 

var lastYearsShipments = myQuery.Products.Where(predicate); 

Need Your Help

how to provide functionality for cut,copy,paste,undo,redo,delete buttons in an web based application

javascript jquery html css

Hi i am creating a web based application where i created buttons for cut,copy,paste,undo,redo,delete options.I wanted to make all these buttons to work according to their functionality after clicki...