QTP - 控制日期是否晚于另一个日期

时间:2015-02-20 11:03:49

标签: string date testing qtp


大家好!我这几天在工作中写了很多剧本,但现在我被困了...... 基本上我需要分析一个参数(一个字符串)并查看它包含的日期是否晚于另一个...
我知道它可能是一个" nooby"问题,但参数是一个字符串,控件是在一个日期的事实完全让我困惑...

它是否像以下一样简单:if参数(" DataAct")> 01/01/2010?!?!

1 个答案:

答案 0 :(得分:1)

查看DateDiff函数:http://www.w3schools.com/vbscript/func_datediff.asp。例如:

diff = DateDiff("d", "02/19/2015", "02/20/2015") ' difference in days
diff = DateDiff("h", "02/19/2015", "02/20/2015") ' difference in hours
diff = DateDiff("n", "02/19/2015", "02/20/2015") ' difference in mins
diff = DateDiff("s", "02/19/2015", "02/20/2015") ' difference in seconds

要计算差异,您需要从字符串中解析出日期并使用DateDiff。

日期的顺序决定了输出。在上面的示例中,所有值都是正数。如果还原它们,输出将导致负数。提供相同的日期/时间将导致0。

diff = DateDiff("d", "02/20/2015", "02/19/2015") ' output = -1
diff = DateDiff("d", "02/20/2015", "02/20/2015") ' output = 0