经典Asp日期比较无法正常工作 [英] Classic Asp date comparison not working correctly

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

问题描述

我的问题中看到了几个相似的标题,但它们的重点是不同的地方.

I have seen couple similar titles with my question but they were focused on different point.

我想问的是,

我正在尝试比较2个日期.是的,听起来超级简单!

I'm trying to compare 2 dates. Yes, sounds super simple!

问题出在这里:

我有两个变量,我试图将这两个变量与Now()进行比较.

I have two variable and I'm trying to compare this 2 variables with Now().

就像:

If startDate < Now() and endDate> Now() Then 
do something....
End If

但是,问题是,当我将startDate(即('2013-08-08 09:30 AM')与Now()和endDate(即'2013-09-09 02:30 PM')与Now()

But the thing is, when I compare startDate (which is ('2013-08-08 09:30 AM') with Now() and endDate (which is '2013-09-09 02:30 PM') with Now()

startDate = '2013-08-08 09:30 AM' 'This value comes from db, I have not typed it. Just trying to show  what it has as a  value.

endDate = '2013-09-09 02:30 PM' 'This value comes from db, I have not typed it. Just trying to show what it has as a  value.

当我比较这两个日期变量时:

and When I compare these 2 date variables:

 If startDate  < Now()  Then 
    do something....
End If

它返回:FALSE.它应该返回TRUE,不是吗?

It returns : FALSE. It supposed to return TRUE, isn't it?

If startDate  > Now()  Then 
        do something....
    End If

它返回:TRUE.它应该返回FALSE,不是吗?

It returns : TRUE. It supposed to return FALSE, isn't it?

 If endDate  < Now()  Then 
        do something....
    End If

但是在这里,它返回正确.我的意思是,这将返回FALSE,这是它应该返回的内容.

But here, it returns correct. I mean this returns FALSE which is what it supposed to return.

那太奇怪了.我已经检查了所有这些变量的值及其比较结果.价值观看起来不错,没有什么看起来很奇怪.但是,当我比较startDate和Now()时,startDate的表现如何像它的实际表现而不是Now()一样,我无法理解.

That's so weird. I have checked all these variables' values and their comparison results. Values look good, nothing looks weird. But when I compare startDate and Now() , how come startDate acts like its greaather than Now() I can't get it.

我尝试过:

     If FormatDateTime(startDate) < FormatDateTime(Now()) Then do something
     If FormatDateTime(CDate(startDate)) < FormatDateTime(CDate(Now())) Then do something
     If DateValue(startDate) < DateValue(Now()) Then do something

还尝试了上述方法中的一些嵌套嵌套.但是没有运气.

Also tried nested paranthesis of some of the above . BUT NO LUCK.

他们都没有工作.

最近两个小时,这个问题使我的大脑有些不适.

This issue just nibbles my brain last couple hours.

希望它有明确的解释.

正在寻找建议

提前谢谢!

NOW()是2013-09-05 12:30 PM

NOW() is 2013-09-05 12:30 PM

推荐答案

我想回答我自己的问题,以帮助遇到相同问题的人.

I would like to answer my own question to help someone who will have same problem.

当我比较

If FormatDateTime(CDate(startDate)) > FormatDateTime(CDate(Now())) Then 
   Do something...
End If

它不能正常工作(这很奇怪,我仍然没明白!)

It has not worked correctly (which is extremely strange, I still didn't get it!)

但是,当我删除FormatDateTime时,就像这样:

However , when I remove, FormatDateTime , like this:

If CDate(startDate) > CDate(Now()) Then 
       Do something...
    End If

它返回正确的值.

我不知道发生了什么变化,但是只能说按预期完成".

I don't know what has been changed but just can say 'Went through as expected' .

谢谢

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

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