You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何DateDiff返回超大负数?VB脚本计时问题求助

Fixing the Huge Negative Time Value in Your VBScript Timer

Hey there! Let's break down why you're getting that wild negative number (-3733642190 seconds) when trying to time your operation, and how to fix it quickly.

Why the Negative Number Happens

That massive negative value is almost certainly due to incorrect time calculation logic—likely using date-based functions (like Now()) that rely on VBScript's internal date timestamp (which counts days since December 30, 1899). If your start/end time calculation crosses an unexpected boundary, or if you mixed up the order of start/end values in a way that triggers integer overflow, you'll end up with nonsensical negative results.

The Simple Fix: Use the Timer Function

VBScript has a built-in Timer function that's perfect for short-duration timing (like your 20-second target). It returns the number of seconds elapsed since midnight as a single-precision float, so it avoids date-related overflow issues entirely.

Here's how to rewrite your code with proper timing:

' Capture start time (seconds since midnight)
Dim startTime
startTime = Timer

' Execute your operation (complete your existing code here)
PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").SelectCell "#1","Contract_Party_Name"
' Add the rest of your page load/operation steps here...

' Capture end time
Dim endTime
endTime = Timer

' Calculate elapsed time (round to 2 decimal places for readability)
Dim elapsedSeconds
elapsedSeconds = Round(endTime - startTime, 2)

' Check if your target is met
If elapsedSeconds < 20 Then
    MsgBox "Operation completed in " & elapsedSeconds & " seconds (meets target!)"
Else
    MsgBox "Operation took " & elapsedSeconds & " seconds (exceeds 20-second target)"
End If

Key Notes

  • Always subtract startTime from endTime—reversing them will give a negative number, but using Timer ensures the value stays within a 0-86400 range (since there are 86400 seconds in a day).
  • Since your target is under 20 seconds, Timer is ideal. For operations that might span multiple days, you'd combine DateDiff with Timer, but that's unnecessary here.

内容的提问来源于stack exchange,提问作者JPWat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:06:21