问:日期和时间问题 [英] Q: Dates and Times Problem

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

问题描述




我有一个包含日期类型列的表格。


我正在尝试查看表格中的某些行使用DataView。


使用过滤器,我可以查看行,例如,日期等于

的东西,例如


vue.RowFilter =" Date =#01/01/03#"


然而,当我尝试类似的东西时


vue.RowFilter =" Date> #01/01/03#AND日期< #02/01/03号"我得到一个空集

虽然这个值有日期!


另外,我想在某些日期和时间内检索行,所以我想要

来做类似的事情:


vue.RowFilter =" Date> #01/01/03 05:03:00#AND#02/01/03 12:00:06#"


但是,我必须得到错误的语法,因为我没有得到

任何行。


希望有人可以提供帮助。


提前致谢


Geoff

Hi

I have a table that has a column with Date types.

I am trying to view certain rows in the table using a DataView.

Using the filter, I can view the rows with, for example, the date equal to
something e.g.

vue.RowFilter = "Date = #01/01/03#"

however, when I try something like

vue.RowFilter = "Date > #01/01/03# AND Date < #02/01/03#" I get an empty set
although there are dates in this value!

Also, I''d like to retrieve rows within certain dates AND times, so I''d like
to do something like:

vue.RowFilter = "Date > #01/01/03 05:03:00# AND #02/01/03 12:00:06#"

However, I must be getting the syntax wrong because again I''m not getting
any rows.

Hope somebody can help.

Thanks in advance

Geoff

推荐答案

Geoff,

我无法重现这个。
使用以下代码(使用Northwind SQL Server示例数据库):

Dim orders As New DataView(customerDataSet.Tables(" Orders)) )

orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<

#2/27/1998#"

每个订单作为DataRowView订单

Debug.WriteLine(order!CustomerID," CustomerID")

Debug.WriteLine(order!OrderId," Order")

Debug.WriteLine(order!OrderDate ,OrderDate)

下一页


请记住,DateTime列包含Date& a时间值,对于

开始日期#2/25/1998#日期将被包括在内,而结束日期

#2/27/1998#,I发现它更容易进入第二天...所以上面的

实际上显示了25日& 26,但不是27 ......你可以包括时间

,例如:


orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<

#2/26/1998 12:00 PM#"





orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<

#2/26/1998 13:00#"


我收到一些显示的行...


请记住日期/时间格式是美国(月/日/年)的日期文字。


希望这有助于

Jay


" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道

news:40 ********************* @ news.dial.pipex.com ..。
Geoff,
I am not able to reproduce this.

Using the following code (using the Northwind SQL Server sample database):
Dim orders As New DataView(customerDataSet.Tables("Orders"))
orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/27/1998#"
For Each order As DataRowView In orders
Debug.WriteLine(order!CustomerID, "CustomerID")
Debug.WriteLine(order!OrderId, "Order")
Debug.WriteLine(order!OrderDate, "OrderDate")
Next

Remember that DateTime columns contain both a Date & a Time value, for the
start Date #2/25/1998# the date will be included, while the end date
#2/27/1998#, I find its easier to go to the next day... So the above
actually displays the 25th & 26th, but not the 27th... You can include time
such as:

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 12:00 PM#"

or

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 13:00#"

I get a handful of rows displayed...

Remember the date/time format is US (month/day/year) in date literals.

Hope this helps
Jay

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. .


我有一个包含Date类型列的表。

我正在尝试使用DataView查看表中的某些行。

使用过滤器,我可以查看行,例如日期等于


vue.RowFilter =" Date =#01/01 / 03#"

然而,当我尝试类似

vue.RowFilter =" Date> #01/01/03#AND日期< #02/01/03号"我得到一个空的
设置虽然这个值有日期!

另外,我想在某些日期和时间内检索行,所以我会
喜欢做类似的事情:

vue.RowFilter =" Date> #01/01/03 05:03:00#AND#02/01/03 12:00:06#"

然而,我必须弄错语法,因为我再次没有得到任何行。

希望有人可以提供帮助。

提前致谢

Geoff
Hi

I have a table that has a column with Date types.

I am trying to view certain rows in the table using a DataView.

Using the filter, I can view the rows with, for example, the date equal to
something e.g.

vue.RowFilter = "Date = #01/01/03#"

however, when I try something like

vue.RowFilter = "Date > #01/01/03# AND Date < #02/01/03#" I get an empty set although there are dates in this value!

Also, I''d like to retrieve rows within certain dates AND times, so I''d like to do something like:

vue.RowFilter = "Date > #01/01/03 05:03:00# AND #02/01/03 12:00:06#"

However, I must be getting the syntax wrong because again I''m not getting
any rows.

Hope somebody can help.

Thanks in advance

Geoff



Geoff,

ToString重载,您可以传递一个格式字符串,以便myStringDate以格式输出

你想要的。

http://msdn.microsoft.com/library/de...ttingtypes.asp

http://msdn.microsoft.com/ library / de ... matstrings.asp


如果myStringDate将作为RowFilter的一部分,我会使用

之类的东西:


''仅获取日期

Const format1 As String =" MM / dd / yyy"
Geoff,
ToString is overloaded, you can pass a format string so myStringDate comes
out in the format you want.

http://msdn.microsoft.com/library/de...ttingtypes.asp

http://msdn.microsoft.com/library/de...matstrings.asp

If myStringDate is going to be as part of the RowFilter I would use
something like:

'' get the date only
Const format1 As String = "MM/dd/yyy"
Dim myStringDate As String = myDate.ToString(format1)


''得到日期&时间

Const format2 As String =" MM / dd / yyy HH:mm:ss" Dim myStringDate As String = myDate.ToString(format2)


希望这有助于

Jay

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在留言中写道

新闻:40 ********************* @ news.dial.pipex.com ..你好杰伊

我认为这可能是格式问题。我将日期对象转换为字符串,并在此过程中交换月和日。这个
是为什么我的排序不起作用的原因即

Dim myDate As Date = any

Dim myStringDate As String = myDate.ToString()''This导致问题

任何人都可以建议工作吗?

Geoff

Jay B. Harlow [MVP - Outlook]" < JA ************ @ msn.com>在消息中写道
新闻:eE ************** @ tk2msftngp13.phx.gbl ...
Dim myStringDate As String = myDate.ToString(format1)
'' get both the date & time
Const format2 As String = "MM/dd/yyy HH:mm:ss" Dim myStringDate As String = myDate.ToString(format2)
Hope this helps
Jay
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. . Hi Jay

I think this may be a problem with format. I am converting the date object
into a string and during the process the month and day are swapped. This is why my sort isn''t working i.e.

Dim myDate As Date = whatever

Dim myStringDate As String = myDate.ToString() '' This causes the problem

Can anybody suggest a work round?

Geoff

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
Geoff,
我不是能够重现这一点。

使用以下代码(使用Northwind SQL Server示例
数据库):
Geoff,
I am not able to reproduce this.

Using the following code (using the Northwind SQL Server sample database):
Dim orders As新DataView(customerDataSet.Tables(" Orders)))
orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<
#2/27/1998#"
对于每个订单As DataRowView在订单中
Debug.WriteLine(订单!CustomerID," CustomerID" ;)
Debug.WriteLine(order!OrderId," Order")
Debug.WriteLine(order!OrderDate," OrderDate")
下一页

记住DateTime列包含Date& a时间值,
开始日期#2/25/1998#日期将被包括在内,而结束日期
#2/27/1998#,我发现它更容易进入下一个那天......所以上面的实际上显示了25日& 26,但不是27 ......你可以包括时间
Dim orders As New DataView(customerDataSet.Tables("Orders"))
orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/27/1998#"
For Each order As DataRowView In orders
Debug.WriteLine(order!CustomerID, "CustomerID")
Debug.WriteLine(order!OrderId, "Order")
Debug.WriteLine(order!OrderDate, "OrderDate")
Next

Remember that DateTime columns contain both a Date & a Time value, for the start Date #2/25/1998# the date will be included, while the end date
#2/27/1998#, I find its easier to go to the next day... So the above
actually displays the 25th & 26th, but not the 27th... You can include time
,例如:

orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<
#2/26/1998 12:00 PM#"



orders.RowFilter =" ; OrderDate> #2/25/1998#和OrderDate<
#2/26/1998 13:00#"

我收到了一些显示的行...
<记住日期/时间格式是美国(月/日/年)的日期文字。

希望这有帮助
杰伊

杰夫琼斯 ; < GE *** @ NODAMNSPAM.com>在消息中写道
新闻:40 ********************* @ news.dial.pipex.com ..。
such as:

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 12:00 PM#"

or

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 13:00#"

I get a handful of rows displayed...

Remember the date/time format is US (month/day/year) in date literals.

Hope this helps
Jay

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. .


我有一个包含Date类型列的表。

我正在尝试使用DataView查看表中的某些行。

>使用过滤器,我可以查看行,例如,日期
Hi

I have a table that has a column with Date types.

I am trying to view certain rows in the table using a DataView.

Using the filter, I can view the rows with, for example, the date


等于某事,例如

vue.RowFilter =" Date =#01/01 / 03#"

然而,当我尝试类似

vue.RowFilter =" Date> #01/01/03#AND日期< #02/01/03号"我得到一个

equal to something e.g.

vue.RowFilter = "Date = #01/01/03#"

however, when I try something like

vue.RowFilter = "Date > #01/01/03# AND Date < #02/01/03#" I get an


空集

虽然这个值有日期!

另外,我想在某些日期内检索行和时间,所以我
although there are dates in this value!

Also, I''d like to retrieve rows within certain dates AND times, so I''d


喜欢

做类似的事情:

vue.RowFilter =" Date> #01/01/03 05:03:00#AND#02/01/03 12:00:06#"

然而,我必须弄错语法,因为我再次没有
to do something like:

vue.RowFilter = "Date > #01/01/03 05:03:00# AND #02/01/03 12:00:06#"

However, I must be getting the syntax wrong because again I''m not


获得任何行。

希望有人可以提供帮助。

提前致谢

杰夫


getting any rows.

Hope somebody can help.

Thanks in advance

Geoff





嗨再次


嗯,我似乎要到达周杰伦。在你的帮助之后,我现在可以在

日期条款中排序,但似乎没有花时间考虑!!!


所以,例如,我正在使用类似的东西:


vue1.RowFilter =" MyDate< #02/05/2004 14:00:00#


给出了02/05/2004之前的所有日期但它没有通知

你能帮忙吗?


Geoff


" Jay B.哈洛[MVP - Outlook]" < JA ************ @ msn.com>在消息中写道

news:uP ************** @ TK2MSFTNGP10.phx.gbl ...
Hi again

Well, I appear to be getting there Jay. After your help, I can now sort in
terms of date but it doesn''t seem to take the time into account!!!

So, for example, I''m using something like:

vue1.RowFilter = "MyDate < #02/05/2004 14:00:00#

which gives all the dates before 02/05/2004 BUT it doesn''t take any notice
of the time.

Can you help?

Geoff

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uP**************@TK2MSFTNGP10.phx.gbl...
Geoff, ToString重载,您可以传递格式字符串,以便myStringDate以您想要的格式出现。

http://msdn.microsoft.com/library/de...ttingtypes。 asp
http://msdn.microsoft.com/library/de...matstrings.asp
如果myStringDate将作为RowFilter的一部分,我将使用<类似于:

''仅获取日期
Const format1 As String =" MM / dd / yyy"
Geoff,
ToString is overloaded, you can pass a format string so myStringDate comes
out in the format you want.

http://msdn.microsoft.com/library/de...ttingtypes.asp
http://msdn.microsoft.com/library/de...matstrings.asp
If myStringDate is going to be as part of the RowFilter I would use
something like:

'' get the date only
Const format1 As String = "MM/dd/yyy"
Dim myStringDate As String = myDate.ToString(format1)
Dim myStringDate As String = myDate.ToString(format1)



''得到日期和时间时间
Const format2 As String =" MM / dd / yyy HH:mm:ss"



'' get both the date & time
Const format2 As String = "MM/dd/yyy HH:mm:ss"

Dim myStringDate As String = myDate.ToString(format2)
Dim myStringDate As String = myDate.ToString(format2)



希望这有帮助
Jay

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道
新闻:40 ********************* @ news.dial.pipex.com ..。



Hope this helps
Jay
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. .

你好杰伊

我认为这可能是格式问题。我将日期
object
Hi Jay

I think this may be a problem with format. I am converting the date object
转换为字符串,并在此过程中交换月份和日期。这个
into a string and during the process the month and day are swapped. This


为什么我的排序不起作用

Dim myDate As Date = what

Dim myStringDate As String = myDate.ToString()''这会导致问题

任何人都建议工作一轮吗?

杰夫

周杰伦B.哈洛[MVP - Outlook]" < JA ************ @ msn.com>写在
消息新闻:eE ************** @ tk2msftngp13.phx.gbl ...
why my sort isn''t working i.e.

Dim myDate As Date = whatever

Dim myStringDate As String = myDate.ToString() '' This causes the problem

Can anybody suggest a work round?

Geoff

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eE**************@tk2msftngp13.phx.gbl...
Geoff,
我不是能够重现这一点。

使用以下代码(使用Northwind SQL Server示例
Geoff,
I am not able to reproduce this.

Using the following code (using the Northwind SQL Server sample


数据库):Dim orders As New DataView(customerDataSet.Tables(") ;订单))
orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<
#2/27/1998#"
对于每个订单As DataRowView在订单中
Debug.WriteLine(订单!CustomerID," CustomerID" ;)
Debug.WriteLine(order!OrderId," Order")
Debug.WriteLine(order!OrderDate," OrderDate")
下一页

记住DateTime列包含Date& a时间值,对于开始日期#2/25/1998#将包括日期,而结束日期
#2/27/1998#,我发现它更容易进入第二天...所以上面的实际上显示了第25个& 26,但不是27 ......你可以包括


database): Dim orders As New DataView(customerDataSet.Tables("Orders"))
orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/27/1998#"
For Each order As DataRowView In orders
Debug.WriteLine(order!CustomerID, "CustomerID")
Debug.WriteLine(order!OrderId, "Order")
Debug.WriteLine(order!OrderDate, "OrderDate")
Next

Remember that DateTime columns contain both a Date & a Time value, for the start Date #2/25/1998# the date will be included, while the end date
#2/27/1998#, I find its easier to go to the next day... So the above
actually displays the 25th & 26th, but not the 27th... You can include


时间

,例如:

orders.RowFilter =" OrderDate> #2/25/1998#和OrderDate<
#2/26/1998 12:00 PM#"



orders.RowFilter =" ; OrderDate> #2/25/1998#和OrderDate<
#2/26/1998 13:00#"

我收到了一些显示的行...
<记住日期/时间格式是美国(月/日/年)的日期文字。

希望这有帮助
杰伊

杰夫琼斯 ; < GE *** @ NODAMNSPAM.com>在消息中写道
新闻:40 ********************* @ news.dial.pipex.com ..
>嗨
>
>我有一个包含日期类型列的表格。
>
>我正在尝试使用DataView查看表中的某些行。
>
>使用过滤器,我可以查看行,例如,日期等于
such as:

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 12:00 PM#"

or

orders.RowFilter = "OrderDate > #2/25/1998# and OrderDate <
#2/26/1998 13:00#"

I get a handful of rows displayed...

Remember the date/time format is US (month/day/year) in date literals.

Hope this helps
Jay

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40*********************@news.dial.pipex.com.. .
> Hi
>
> I have a table that has a column with Date types.
>
> I am trying to view certain rows in the table using a DataView.
>
> Using the filter, I can view the rows with, for example, the date equal
>例如
>
> vue.RowFilter =" Date =#01/01/03#"
>
>但是,当我尝试类似
>
>的时候vue.RowFilter =" Date> #01/01/03#AND日期< #02/01/03号"我得到一个
> something e.g.
>
> vue.RowFilter = "Date = #01/01/03#"
>
> however, when I try something like
>
> vue.RowFilter = "Date > #01/01/03# AND Date < #02/01/03#" I get an


空集
>虽然这个值有日期!
>
>此外,我想在特定日期和时间内检索行,所以
我想要
>做类似的事情:
>
> vue.RowFilter =" Date> #01/01/03 03:03:00#AND#02/01/03 12:00:06#"
>
>但是,我必须得到语法错误,因为我不是


empty set
> although there are dates in this value!
>
> Also, I''d like to retrieve rows within certain dates AND times, so I''d like
> to do something like:
>
> vue.RowFilter = "Date > #01/01/03 05:03:00# AND #02/01/03 12:00:06#"
>
> However, I must be getting the syntax wrong because again I''m not


得到

>任何行。
>
>希望有人可以提供帮助。
>
>在此先感谢
>
> Geoff
>
>
> any rows.
>
> Hope somebody can help.
>
> Thanks in advance
>
> Geoff
>
>





这篇关于问:日期和时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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