日期比较 [英] Date Comparison

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

问题描述

这是比较两个日期的代码


如果(CalendarDate1> = CalendarDate2)那么

MsgBox"请输入正确的日期范围" ;,vbOKOnly + vbExclamation,

" SASMonitor"

退出Sub

结束如果

以下代码是我从user.i获取日期我的表格中有两个日历

组件。这就是为什么两个日历


Private Sub Calendar1_Click()

CalendarDate1 =修剪(格式(Calendar1.Value," dd-mm-yy"))

Command1.Enabled = False

MsgBox CalendarDate1

End Sub

Private Sub Calendar2_Click()

CalendarDate2 = Trim(格式(Calendar2.Value," dd-mm-yy" ))

Command1.Enabled = False

Command3.SetFocus

MsgBox CalendarDate2

End Sub

''当我这样做时,我无法得到正确的比较。案例是

i选择2004年5月10日fr在第一个日历和2004年6月1日的第二个日历中,它表示2004年10月10日更大。请帮助我。

提前致谢。

This is the code that compares the two dates

If (CalendarDate1 >= CalendarDate2) Then
MsgBox "Please enter the correct date range", vbOKOnly + vbExclamation,
"SASMonitor"
Exit Sub
End If
The below code is where i get the date from the user.i have two calendar
components in my form.that''s why two calendar

Private Sub Calendar1_Click()
CalendarDate1 = Trim(Format(Calendar1.Value, "dd-mm-yy"))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub
Private Sub Calendar2_Click()
CalendarDate2 = Trim(Format(Calendar2.Value, "dd-mm-yy"))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
End Sub
''when i do this i am not able to get the correct comparison.the case is when
i select 10th may 2004 from the first calendar and 1st june 2004 from the
second calendar,it says that 10th may 2004 is greater.pls help me.
Thanks in advance.

推荐答案

Kurien Baker Fenn< Ku ************* @ discussion.microsoft.com>写道:
Kurien Baker Fenn <Ku*************@discussions.microsoft.com> wrote:
这是比较两个日期的代码

If(CalendarDate1> = CalendarDate2)然后
MsgBox"请输入正确的日期范围" ,vbOKOnly + vbExclamation,
SASMonitor
退出Sub
结束如果

以下代码是我从user.i获取日期的地方。我有两个日历
组件在我的表格中。这就是为什么两个日历

私人子Calendar1_Click()
CalendarDate1 =修剪(格式(Calendar1.Value," dd-mm-yy" ;))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub

私有子Calendar2_Click()
CalendarDate2 =修剪(格式(Calendar2.Value) ,dd-mm-yy))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
结束子

''何时我这样做我无法得到正确的比较。案例是当我选择从2004年第一个日历和2004年6月1日起的2004年第10期
第二个日历,它说2004年10月10日更大。请帮助我。
This is the code that compares the two dates

If (CalendarDate1 >= CalendarDate2) Then
MsgBox "Please enter the correct date range", vbOKOnly + vbExclamation,
"SASMonitor"
Exit Sub
End If
The below code is where i get the date from the user.i have two calendar
components in my form.that''s why two calendar

Private Sub Calendar1_Click()
CalendarDate1 = Trim(Format(Calendar1.Value, "dd-mm-yy"))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub
Private Sub Calendar2_Click()
CalendarDate2 = Trim(Format(Calendar2.Value, "dd-mm-yy"))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
End Sub
''when i do this i am not able to get the correct comparison.the case is when
i select 10th may 2004 from the first calendar and 1st june 2004 from the
second calendar,it says that 10th may 2004 is greater.pls help me.




什么是CalendarDate1和CalendarDate2声明为什么?你正在使用它们

,好像它们是在顶部的日期,但随着字符串降低。你应该在做比较之前将它们作为DateTimes来获得它们。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



What are CalendarDate1 and CalendarDate2 declared as? You''re using them
as if they''re dates at the top, but as strings lower down. You should
get them as DateTimes before doing comparisons.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Kurien Baker Fenn< Ku ****** *******@discussions.microsoft.com>写道:
Kurien Baker Fenn <Ku*************@discussions.microsoft.com> wrote:
这是比较两个日期的代码

If(CalendarDate1> = CalendarDate2)然后
MsgBox"请输入正确的日期范围" ,vbOKOnly + vbExclamation,
SASMonitor
退出Sub
结束如果

以下代码是我从user.i获取日期的地方。我有两个日历
组件在我的表格中。这就是为什么两个日历

私人子Calendar1_Click()
CalendarDate1 =修剪(格式(Calendar1.Value," dd-mm-yy" ;))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub

私有子Calendar2_Click()
CalendarDate2 =修剪(格式(Calendar2.Value) ,dd-mm-yy))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
结束子

''何时我这样做我无法得到正确的比较。案例是当我选择从2004年第一个日历和2004年6月1日起的2004年第10期
第二个日历,它说2004年10月10日更大。请帮助我。
This is the code that compares the two dates

If (CalendarDate1 >= CalendarDate2) Then
MsgBox "Please enter the correct date range", vbOKOnly + vbExclamation,
"SASMonitor"
Exit Sub
End If
The below code is where i get the date from the user.i have two calendar
components in my form.that''s why two calendar

Private Sub Calendar1_Click()
CalendarDate1 = Trim(Format(Calendar1.Value, "dd-mm-yy"))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub
Private Sub Calendar2_Click()
CalendarDate2 = Trim(Format(Calendar2.Value, "dd-mm-yy"))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
End Sub
''when i do this i am not able to get the correct comparison.the case is when
i select 10th may 2004 from the first calendar and 1st june 2004 from the
second calendar,it says that 10th may 2004 is greater.pls help me.




什么是CalendarDate1和CalendarDate2声明为什么?你正在使用它们

,好像它们是在顶部的日期,但随着字符串降低。你应该在做比较之前将它们作为DateTimes来获得它们。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



What are CalendarDate1 and CalendarDate2 declared as? You''re using them
as if they''re dates at the top, but as strings lower down. You should
get them as DateTimes before doing comparisons.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too





Jon Skeet [C#MVP]"写道:


"Jon Skeet [C# MVP]" wrote:
Kurien Baker Fenn< Ku ************* @ discussion.microsoft.com>写道:
Kurien Baker Fenn <Ku*************@discussions.microsoft.com> wrote:
这是比较两个日期的代码

If(CalendarDate1> = CalendarDate2)然后
MsgBox"请输入正确的日期范围" ,vbOKOnly + vbExclamation,
SASMonitor
退出Sub
结束如果

以下代码是我从user.i获取日期的地方。我有两个日历
组件在我的表格中。这就是为什么两个日历

私人子Calendar1_Click()
CalendarDate1 =修剪(格式(Calendar1.Value," dd-mm-yy" ;))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub

私有子Calendar2_Click()
CalendarDate2 =修剪(格式(Calendar2.Value) ,dd-mm-yy))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
结束子

''何时我这样做我无法得到正确的比较。案例是当我选择从2004年第一个日历和2004年6月1日起的2004年第10期
第二个日历,它说2004年10月10日更大。请帮助我。
This is the code that compares the two dates

If (CalendarDate1 >= CalendarDate2) Then
MsgBox "Please enter the correct date range", vbOKOnly + vbExclamation,
"SASMonitor"
Exit Sub
End If
The below code is where i get the date from the user.i have two calendar
components in my form.that''s why two calendar

Private Sub Calendar1_Click()
CalendarDate1 = Trim(Format(Calendar1.Value, "dd-mm-yy"))
Command1.Enabled = False
MsgBox CalendarDate1
End Sub
Private Sub Calendar2_Click()
CalendarDate2 = Trim(Format(Calendar2.Value, "dd-mm-yy"))
Command1.Enabled = False
Command3.SetFocus
MsgBox CalendarDate2
End Sub
''when i do this i am not able to get the correct comparison.the case is when
i select 10th may 2004 from the first calendar and 1st june 2004 from the
second calendar,it says that 10th may 2004 is greater.pls help me.



什么是CalendarDate1和CalendarDate2声明为什么?你正在使用它们好像它们是在顶部的日期,但随着字符串降低。在进行比较之前,你应该把它们作为DateTimes。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复群组,请不要给我发邮件



What are CalendarDate1 and CalendarDate2 declared as? You''re using them
as if they''re dates at the top, but as strings lower down. You should
get them as DateTimes before doing comparisons.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



i将Calendardate1和calendardate2声明为dim.so我应该怎么办

比较。请帮助


在此先感谢


i declared Calendardate1 and calendardate2 as dim.so what should i do to
compare.Please help

Thanks in Advance


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

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