Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF数据服务[WebGet]日期时间参数_C#_Mysql_Wcf_Datetime_Webget - Fatal编程技术网

C# WCF数据服务[WebGet]日期时间参数

C# WCF数据服务[WebGet]日期时间参数,c#,mysql,wcf,datetime,webget,C#,Mysql,Wcf,Datetime,Webget,我试图将2个datetime参数传递到我的webget中,但我不知道如何使其正常工作。我将在下面向您展示我的代码和我得到的错误,也许有人知道这是如何工作的 [WebGet] public IQueryable<TestTable> GetCallersByDate(string beginDate, string eindDate) { testCDREntities context = this.CurrentDataSource; DateTim

我试图将2个datetime参数传递到我的webget中,但我不知道如何使其正常工作。我将在下面向您展示我的代码和我得到的错误,也许有人知道这是如何工作的

[WebGet]
public IQueryable<TestTable> GetCallersByDate(string beginDate, string eindDate)
{
        testCDREntities context = this.CurrentDataSource;

        DateTime startDt = DateTime.Parse(beginDate);
        DateTime endDt = DateTime.Parse(eindDate);



        var selectedOrders = from table in context.TestTables
                             where table.Created >= startDt && table.Created <= endDt
                             select table;

        return selectedOrders; 
}

我希望有人能帮我

根据下面的数据,您应该使用DateTime.ParseExact而不是通常的DateTime.Parse

我们可以看到日期字符串的格式是yyyy/MM/ddTHH:MM:ss,并且认为该格式不是.NET的固有格式

beginDate=2016/03/23T20:22:30:14 eindDate=2016/03/2T20:13:11:03

string dateFormat = "yyyy/MM/ddTHH:mm:ss";

DateTime startDt = DateTime.ParseExact(beginDate, dateFormat, CultureInfo.InvariantCulture);
DateTime endDt = DateTime.Parse(eindDate, dateFormat, CultureInfo.InvariantCulture);

至少这些斜杠会有问题,URL编码你的数据。谢谢你的帮助,你是惊人的!
string dateFormat = "yyyy/MM/ddTHH:mm:ss";

DateTime startDt = DateTime.ParseExact(beginDate, dateFormat, CultureInfo.InvariantCulture);
DateTime endDt = DateTime.Parse(eindDate, dateFormat, CultureInfo.InvariantCulture);