MSQL 2005日期时间问题 [英] MSQL 2005 Date Time Problem
本文介绍了MSQL 2005日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有1,2,3,4,5,6,7,8,9,10个日期数据到db中.现在我想显示第8个日期数据.我有两个名为StartDate,EndDate的日期时间选择器.
我已经使用sql quary
Suppose I have 1,2,3,4,5,6,7,8,9,10 dates data into db. Now I want to show the 8th date data.I have tow date time picker named StartDate, EndDate.
I have use sql quary
Select * from [table_name] where (received_date BETWEEN @StardDate AND @EndDate)
@StardDate=8th date
@EndDate=8th date
如果我使用上面的代码,那么我什么也没找到.但是如果我设置
If I use the above code then I found nothing. But if I set
@StardDate=8th date
@EndDate=9th date
然后我找到结果.
你能解释出什么问题吗?
请注意:我正在使用MSSQL205和ASP.NET(c#)
Then I find the result.
Can u explain what is the problem.
Note that: I am using MSSQL205 and ASP.NET(c#)
推荐答案
检查这两种日期格式.这可以帮助您创建查询
Check these two date formatting. This may help you to create your query
SELECT CONVERT(VARCHAR(10), GETDATE(), 102)
SELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 102), 102)
它具有与时俱进.基本上,如果您说在6月8日00:00至6月8日00:00之间,将永远不会有任何结果.
尝试在6月8日00:00和6月8日23:59:59之间"获得预期的结果.
因此,在c#中,当您创建要传递的日期时,请在DateTime参数中初始化时间.
干杯.
It has to do with the times. Basically, if you say ''between Jun 8 00:00 and Jun 8 00:00 there will never be any results.
Try ''between Jun 8 00:00 and Jun 8 23:59:59'' for your expected result.
So, in c# when you create the dates to pass in, initialize the time in the DateTime parameter.
Cheers.
这篇关于MSQL 2005日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文