对于c#的开发的网页程式,一些企业或者工厂可能会运用这些程式去查询一些资料,考虑到查询的资料太多,假如一个月的资料就有上万条数据,在对于查询资料的sql语句后时间栏位运用between…..and……对查询时间范围进行控制,以免捞取数据太多,查询时间较长。

         根据判断输入的时间范围返回的结果是true或者false来进行处理。已限制一个月(30天)的查询时间为例,代码如下:

 

 private bool checkdatetimescope()
        {
            datetime fd = convert.todatetime(param.inform.value);
            datetime ed = convert.todatetime(param.inend.value);

            if (((timespan)(ed - fd)).days < 30)
            {
                return true;
            }
            else
            {
                scriptmanager.registerstartupscript(this.page, this.gettype(), "alertform", "alert('start date to end date must not large than 30 days ! ');", true);
                return false;
            }
        }