根据当前日期时间从移动服务查询数据库

本文关键字:服务 查询 数据库 移动 当前日期 时间 | 更新日期: 2023-09-27 18:29:54

我使用以下代码行成功地从azure移动服务查询了azure sql数据库:

var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(complete%20eq%20true)");

我想我可以修改这个以适应我的具体目标。我的目标是查询数据库以返回Notification1列中的值与当前Datetime:匹配的记录

DateTime currentTime = DateTime.Now;
currentTime = currentTime.AddMilliseconds(-currentTime.Millisecond);
string timeString = currentTime.ToString();
var targetUri = new Uri("https://studytoolmobile.azure-mobile.net/tables/TodoItem?$filter=(Notification1%20eq%20" + timeString + ")");

问题是它给了我一个错误:

'The remote server returned an error: (400) Bad Request.'.

这让我相信这是由我正在使用的新Uri引起的。

有人知道实现这一目标的正确uri是什么吗?还是我的错误有其他原因?非常感谢。

根据当前日期时间从移动服务查询数据库

您需要使用正确的OData DateTime文本语法。例如:

$filter=(Notification1 eq datetime'2010-01-25T02:13:40.1374695Z')

您可以使用currentTime.ToString("o")DateTime实例中获取所需的ISO格式值。