我有用于比较2的LINQ查询-DateTimes(24小时时间), [英] I have LINQ query for compare 2 - DateTimes(24-hr time),

查看:77
本文介绍了我有用于比较2的LINQ查询-DateTimes(24小时时间),的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老兄,

我有LINQ查询要比较2次,

Hi dude,

I have LINQ query for compare 2 times,

Inputs: Opening time  : 09:00 and Closing time  : 21:00




表字段是




Table fields are,


  Id        Openingtime         Closingtime
  1         08:45                 20:00
  2         09:00                 19:30
  3         10:00                 21:00
  4         9:45                  20:30
  5         9:15                  22:00



我的查询是,

在这段时间之间,

结果:



My Query Is,

in between time how i get,

results:

3         10:00                 21:00
5         9:15                  22:00



回复我.



reply me.

推荐答案

以下代码可用于根据需要过滤数据
The following code can be used to filter the data as required
void Main()
{
    DataTable timeData = new DataTable();
    timeData.Columns.Add("Id",typeof(int),null);
    timeData.Columns.Add("OpeningTime",typeof(TimeSpan),null);
    timeData.Columns.Add("ClosingTime",typeof(TimeSpan),null);
    
    timeData.Rows.Add(1,new TimeSpan(8,45,0),new TimeSpan(20,0,0));
    timeData.Rows.Add(2,new TimeSpan(9,0,0),new TimeSpan(19,30,0));
    timeData.Rows.Add(3,new TimeSpan(10,0,0),new TimeSpan(21,0,0));
    timeData.Rows.Add(4,new TimeSpan(9,45,0),new TimeSpan(20,30,0));
    timeData.Rows.Add(5,new TimeSpan(9,15,0),new TimeSpan(22,0,0));
    
    TimeSpan openingTime = new TimeSpan(9,0,0);
    TimeSpan closingTime = new TimeSpan(21,0,0);
    
    var enclosedTime = timeData.AsEnumerable().Where (
    	d => d.Field<timespan>("OpeningTime").CompareTo(openingTime) >=0 
        	&& d.Field<timespan>("ClosingTime").CompareTo(closingTime) >=0)
    	.Select (d => d).CopyToDataTable();
}


我在回复你.因为那是最接近您所问问题的东西.
I am replying you. Since that is the closest thing to a question that you asked.


这是SQL QUERY:

This is SQL QUERY:

select Count(*) from restauranttimings where (Convert(varchar(8),openingtime,108)<CONVERT(VARCHAR(8),GETDATE(),108)) and
         (Convert(varchar(8),closingtime,108)>CONVERT(VARCHAR(8),GETDATE(),108)) and holidayreason!='NULL' and days='tuesday'


这篇关于我有用于比较2的LINQ查询-DateTimes(24小时时间),的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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