Reputation:
Trying to parse datetime into an OData query. Tried a lot of different syntaxes but I keep getting errors, albeit different - still errors. If anyone has an idea what could be wrong in my syntax, the help is appreciated.
Error:
{"code":"BadRequest","message":"Syntax error at position 13 in 'Date ge 17-01-2024 00:00:00'."}
Code:
DateTime date1 = new DateTime(2024,01,17);
// Hent Linjer
var data = context.Kapbehov.AddQueryOption("$filter", "Date ge "+date1);'
I tried a lot of variations e.g. datetime before the date, different formats on the date etc.
The table I'm trying to get data from is setup as such;
"Starting_Time": "07:00:00",
"Starting_Date_Time": "2024-01-23T07:00:00Z",
"Ending_Time": "08:35:00",
"Ending_Date_Time": "2024-01-23T08:35:00Z",
"Date": "2024-01-23",
The table is an OData endpoint from web services in business central - if that makes a difference?
Upvotes: 0
Views: 1063
Reputation:
Figured it out myself...
even though it is set up as datetime at the Odata endpoint, the query still takes strings as opposed to datetime. Meaning datetime includes the " ' " symbol.
This works;
string date1 = "2024-01-17";
string date2 = "2024-01-30";
// Hent Linjer
var data = context.Kapbehov.AddQueryOption("$filter", "Date ge " + date1 + " and Date le " + date2);
Upvotes: 1