从数据表中过滤时间 [英] Filter time from datatable

查看:127
本文介绍了从数据表中过滤时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想过滤掉基于uplon查询的时间

我正在从数据库中恢复时间和ToTime

它是来这样吧

Hi
I want to filter out the time based uplon query
I am retreving From Time and ToTime from the database
it is coming like this

FromTime         ToTime
2:30 PM          4:30 PM
11:30 AM        11:30 AM
5:30 PM          7:30 PM
4:30 PM           1:30 AM
1:30 AM           2:30 AM
6:30 AM          12:30 PM
10:30 PM         8:30 AM



我写了linq查询查询数据表

并过滤掉时间12:00 AM和09:00 AM


I have written linq query which query's the datatable
and filters out Time Between 12:00 Am and 09:00 AM

var time = from i in dt.AsEnumerable()
                          where DateTime.Parse(i.Field<string>("FromTime"), CultureInfo.InvariantCulture) >= DateTime.Parse("12:00 AM", CultureInfo.InvariantCulture)
                              && DateTime.Parse(i.Field<string>("ToTime"), CultureInfo.InvariantCulture) <= DateTime.Parse("09:00 AM", CultureInfo.InvariantCulture)
                          select i;





但是过滤没有正确完成任何人都可以让我知道我哪里出错了



But the filtering is not done properly can any one let me know where i am going wrong

推荐答案

看起来你的查询工作正常是基于它是怎么回事写了

你说:

FromTime> = 12 AM

和ToTime< = 9AM



你得到的结果集有FromTime> = 12AM(下午4:30,凌晨1:30和晚上10:30)

和ToTime< = 9AM(凌晨1:30, 2:30 AM,8:30 AM)



如果你想BETWEEN试试

(FromTime> = 12AM && FromTime< = 9AM)

AND(ToTim e> = 12AM && ToTime< = 9AM)
it looks like your query is working correctly based on how it is written
you said:
FromTime >= 12AM
and ToTime <= 9AM

The result set you are getting has FromTime >= 12AM (4:30PM, 1:30AM and 10:30PM)
and ToTime <= 9AM (1:30 AM, 2:30AM, 8:30AM)

if you want BETWEEN try
(FromTime >= 12AM && FromTime <= 9AM)
AND (ToTime >= 12AM && ToTime <= 9AM)


这篇关于从数据表中过滤时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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