在具有解析字符串值的MS SQL 2008服务器中过滤datetime列 [英] Filter datetime column in MS SQL 2008 server with a parsed string value

查看:124
本文介绍了在具有解析字符串值的MS SQL 2008服务器中过滤datetime列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使这个问题的标题更具体。



我正在使用ASP.NET MVC3应用程序。在那里,我使用jQuery网格来显示数据库中的数据,并且几乎没有过滤器。其中一个应该允许用户按日期搜索。



在我的数据库中, Date 列如下所示:





我将所选日期传递到后端,我解析日期字符串如下:

  else if(property.PropertyType == typeof(DateTime))
{
DateTime值;
if(DateTime.TryParse(rule.Data,out value))
{
selector = ExpressionEquals< T>(rule.Field,value);
}
}

变量 / code>如下所示: 03/06/2013 12:24:30



问题在于,在我的数据库中, Date 列具有不同的格式,至少与我在Management Studio中可以看到的一样,实际上我不想过滤器如此具体(时间仅限于用户信息,但实际上只需要日期)。



我需要使来自jQuery网格的数据可用于我想要的搜索类型。实际上,来自网格的日期字符串看起来和解析的值完全相同。换句话说, rule.Data 的值是03/06/2013 12:24:30。 p>

如何使用这些数据只是按日期过滤数据,但是保持表格列类型为 datetime

解决方案

按03/06/2013 00:00:00.000和03/06/2013 23:59:59.999


I'm not sure how I can make the title of this question more specific.

I am working on an ASP.NET MVC3 application. There I use jQuery grid to show data from the database and have few filters. One of them should allow the user to search by date.

In my database the Date column looks like this :

I pass the selected date to the back end where I parse the date string like this :

 else if (property.PropertyType == typeof(DateTime))
                        {
                            DateTime value;
                            if (DateTime.TryParse(rule.Data, out value))
                            {
                                selector = ExpressionEquals<T>(rule.Field, value);
                            }
                        }

Where the variable value looks like this : 03/06/2013 12:24:30.

The problem is that in my database the Date column has a different format at least from what I can see in the Management Studio, and along with that in fact I don't want to filter so specifically (The time is only for user information, but in fact I need only the date).

I need make the data from the jQuery grid usable for the kind of search I want. In fact the date string that comes from the grid looks exactly like the parsed value. In other words the rule.Data value is "03/06/2013 12:24:30".

How can use this data to filter data only by date but keeping the table column type of datetime?

解决方案

Filter by range between "03/06/2013 00:00:00.000" and "03/06/2013 23:59:59.999"

这篇关于在具有解析字符串值的MS SQL 2008服务器中过滤datetime列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆