[英]SQL Query with Long Date Time?
I am trying to pass a SQL query through c# , currently it is based on just the day month and year with time always set to 0 EG 1997-10-28 00.00.00.000 which is great as the time never changes it easy for me to just Select Where date equals the calendar date. 我试图通过c#传递SQL查询,目前它只基于日期和年份,时间总是设置为0 EG 1997-10-28 00.00.00.000这很好,因为时间永远不会改变我很容易只需选择日期等于日历日期。
However with the Start Field , the time is different on each record , eg 1899-12-30 14.14:00.00.000 , 1899-12-30 15.14:30.00.000 . 但是对于开始字段,每个记录的时间不同,例如1899-12-30 14.14:00.00.000,1899-12-30 15.14:30.00.000。 (Seconds downwards are always the same) .
(向下的秒数总是相同的)。
So I need to have a query that will return all the results of the selected date on the "Start" field . 所以我需要有一个查询,它将返回“开始”字段中所选日期的所有结果。 How would I do this?.
我该怎么做?
EG IF i click the calendar which passes 1997-10-28 00.00.00.000 , I would like the results of every time in that day!. EG如果我点击1997-10-28 00.00.00.000的日历,我想在那一天的每次结果! How do I go about that?.
我该怎么做?
Thanks for any input. 感谢您的任何意见。
EDIT: Is there a way to format the date that i have in SQL ?. 编辑:有没有办法格式化我在SQL中的日期? This comes from an old access database!.
这来自一个旧的访问数据库! and as you can see above it is 1899-12-30 ?.
正如你在上面看到的那样它是1899-12-30? not 1998 , I don't know why this has happened!.
不是1998年,我不知道为什么会发生这种情况!
您需要在今天和明天之间选择所有记录,而不包括明天的日期。
WHERE EventDate >= StartDate AND EventDate < DATEADD(d, 1, StartDate)
WHERE DATEDIFF(dd, your_start_field, @your_param) = 0
Can you not just query the date part. 你能不能只查询日期部分。 I think this should work...
我认为这应该有效......
SELECT * FROM Table1 WHERE StartDate = '1997-10-28'
EDIT: Above may not work but following should cover needs 编辑:上面可能不起作用,但以下应涵盖需求
SELECT * FROM Table1 WHERE StartDate >= '1997-10-28 00:00:00.000' AND StartDate < '1997-10-29 00:00:00.000'
(notice the second date is the following date) (注意第二个日期是以下日期)
This SQL DATEADD(d,datediff(d,0,startdate),startdate)
will convert a date with time to just the date; 这个SQL
DATEADD(d,datediff(d,0,startdate),startdate)
将日期与时间转换为日期;
eg 例如
Select field1,field2 from mytable where DATEADD(d,datediff(d,0,startdate),startdate)='1997-10-28'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.