ObjectQuery passing datetime in Where where parameter

How to pass the Date Time value here?

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= 11/4/2009 5:06:08 PM)");

my sample code above seems to work.

even with that

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= \"11/4/2009 5:06:08 PM\")");

I got a cast error in EDM.

+3
source share
2 answers

The following should work:

ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("(it.StartDate >= DATETIME'11/4/2009 17:06:08')");

For more information about literals in ESQL queries, see the documentation .

+4
source

Unfortunately for me @pmarflee's answer does not work. I found another solution matching MSDN :

Part of the date should be in the format: YYYY-MM-DD , where YYYY is the four significant year value between 0001 and 9999, MM is the month between 1 and 12 and DD is the day value that is valid for the given month MM.

: HH: MM [: SS [.fffffff]], HH 0 23, - 0 59, SS - 0 59, fffffff - 0 9999999. . . ; . , .

DATETIME , .

DATETIME'2006-10-1 23:11 '
DATETIME'2006-12-25 01: 01: 00.0000000' - , DATETIME'2006-12-25 01:01 '

:

DateTime dateTimeValue = DateTime.Now;
// ESQL DATETIME format MUST be <yyyy-MM-dd HH:mm> format                                 
_Query = _Query.Where(string.Format("(it.StartDate >= DATETIME'{0:yyyy-MM-dd HH:mm}')",dateTimeValue);
+5

Source: https://habr.com/ru/post/1721861/


All Articles