2016-04-27 71 views
0

我在這件事上很難找到細節。我使用Sharepoint 2010並使用REST獲取我的數據。我想使用REST查詢的日期範圍:REST - 單行文本列上的日期範圍過濾器

http://localhost/_vti_bin/listdata.svc/TEST?$filter=(Column2 ge datetime'2016-04-06') and (Column2 lt datetime'2016-04-09') 

但我得到一個錯誤:

Opérateur 'ge' incompatible avec les types d'opérande 'System.String' et 'System.DateTime' à la position 20. 

對不起它在法國,但大致可以翻譯爲「GE」運營商與「系統不兼容.String'和'System.DateTime'類型。

這裏是我的列的一個例子,它們都是單行文本列。

Column1 Column2    Column3 
BLah  2016-04-01 16:00 Blah1 
Blahs  2016-04-02 16:00 Blahs2 
Blhass  2016-04-03 16:00 Blahss3 
Blhasss 2016-04-06 16:00 Blhasss4 
sBlah  2016-04-08 16:00 sBlah5 
ssBlah  2016-04-08 16:00 ssBlah6 
sssBlah 2016-04-09 16:00 sssBlah7 

有人會理解它是這樣做嗎?

回答

0

抱怨的原因是您使用的格式只適用於比較實際日期字段;列表中的字段是單行文本字段。

幸運的是,您已將日期字符串格式化爲使得它們的字母順序與其時間順序很好地對應。

因此,只要您不嘗試將比較值轉換爲日期時間,您就可以執行相同的過濾邏輯來檢索您的項目範圍;把它們當作一個字符串。

$filter=(Column2 ge '2016-04-06') and (Column2 lt '2016-04-09')

+0

嗯,非常感謝你的伎倆! –