Sql选择在Opartor之间查询日期 [英] Sql Select Query for Between Opartor For date

查看:85
本文介绍了Sql选择在Opartor之间查询日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计,

我想申请在运营商之间查找两个日期之间的数据,我写了这段代码,但它只发现了两天。就像假设我写1-10-2008和5-11-2008那样它找到1到5之间的数据而不是月和年。如何从整个日期查找数据请回复我... !!!



我使用数据类型Varchar(Max)然后在替换varchar后我使用Datetime But它找不到......请回复我...... !!!



我的代码在下面

Hey Guys,
I Want to apply Between Operator for to find data between Two dates and I write this code but it find only through two day. as like suppose I write 1-10-2008 and 5-11-2008 then it find data between 1 and 5 not from month and year. How to do find data from whole Date Please Reply Me...!!!

I use data type Varchar(Max) and then after replace varchar I use Datetime But It Can''t Find...Please Reply Me...!!!

My Code is Below

SqlDataAdapter da1 = new SqlDataAdapter("select * from bill_detail where Date BETWEEN '" + dt1 + "' AND '" + dt2 + "'", con);

推荐答案

请尝试以下方法:

Try the following:
select * from bill_detail where Date >= '" + dt1 + "' AND Date <= '" + dt2 + "'" 


可能在这里:



Sql选择Opartor之间的查询日期 [ ^ ]
may be here :

Sql Select Query for Between Opartor For date[^]


尝试传递适当的日期。默认情况下,日期格式为长字符串,包括日期,时间,日期。



使用语法格式化日期:



假设你从文本框中取出日期,那么语法应该是这样的。



string strDate = txtDate.ToString (dd / MM / yyyy);



或您可以根据您的要求使用任何日期格式



MM / dd / yyyy

yyyy / MM / dd

等..
Try to pass the appropriate date. By default the date format will be a long string which includes date, time, day..

Use the syntax to format the date:

Let''s say you are taking date from textbox then the syntax should be this way.

string strDate = txtDate.ToString("dd/MM/yyyy");

or you can use any date format based on your requirement

MM/dd/yyyy
yyyy/MM/dd
etc..


这篇关于Sql选择在Opartor之间查询日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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