简体   繁体   English

从此日期获取行到此日期

[英]Getting rows from this date to this date

i really couldn't get it. 我真的无法得到它。

code- 码-

select * 
from Bill_Detail 
where DateTimeofBilling > '8/18/2013 12:00:00 PM' 
  and DateTimeofBilling < '8/20/2013 12:00:00 AM'

psudocode- psudocode-

select all 
from Bill_Detail 
where DateTimeofBilling greater than 8/18/2013 
  and DateTimeofBilling less than 8/20/2013

i need to get the rows from the date 8/18/2013 to 8/20/2013 but the code returns nothing. 我需要获取从2013年8月18日到2013年8月20日的行,但代码不返回任何内容。

i think this is enough explanation for this . 我认为这是对此的充分解释。 can anyone help? 有人可以帮忙吗?

Why do you use PM (noon, not midnight) for the "greater than" check? 为什么你使用PM (中午,而不是午夜)进行“大于”检查? Your pseudocode assumes that you also want to use PM. 您的伪代码假定您也想使用PM。

select * 
from Bill_Detail 
where DateTimeofBilling >= '20130818'-- if you want to include this day completely
  and DateTimeofBilling < '20130820' -- if you want to exclude this day completely

尝试这个..

select * from Bill_Detail where DateTimeofBilling > '2013/08/18 12:00:00 PM' and DateTimeofBilling < '2013/08/20 12:00:00 AM'

If your column DateTimeofBilling is type datetime, compare it with date and not with varchar: 如果您的列DateTimeofBilling是类型datetime,请将其与日期进行比较,而不是与varchar进行比较:

select * 
from Bill_Detail 
where
    DateTimeofBilling >= convert(date, '20130818', 112) and
    DateTimeofBilling < convert(date, '20130821', 112)

this one will return you rows with DateTimeofBilling where date is more or equal 2013-08-18 and less or equal 2013-08-20 这个将返回DateTimeofBilling的行,其中日期大于或等于2013-08-18且小于或等于2013-08-20

Using between 之间使用

SELECT *
FROM Bill_Detail
WHERE DateTimeofBilling BETWEEN '20130818 000000' 
    AND DateTimeofBilling < '2013/08/20 12:00:00 AM'

尝试这个,

select * from Bill_Detail where DateTimeofBilling between '8/18/2013 12:00:00 PM' and  '8/20/2013 12:00:00 AM'
SELECT * FROM Bill_Detail WHERE DateTimeofBilling>='8/18/2013 12:00:00 PM' AND DateTimeofBilling<='8/20/2013 12:00:00 AM' ORDER BY DateTimeofBilling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM