Please tell me the specifications of the comparison between dates on VBS.

Asked 1 years ago, Updated 1 years ago, 72 views

The results of the date comparison are counterintuitive.

x=#1899-12-3000:00#
y=#1899-12-30 12:00:00#
If x <y Then
    MsgBox "OK" 'This is displayed
Else
    MsgBox "NG"
End If

x=#1899-12-2900:00:00#
y=#1899-12-29 12:00:00#
If x <y Then
    MsgBox "OK"
Else
    MsgBox "NG" 'This is displayed
End If

Why?

vbs

2022-09-30 20:28

1 Answers

"Please tell me the specifications for adding dates to each other on VBS" answer, because the internal expression compares the size and size.

The example that shows OK is after the date (1899/12/30) when the internal expression is 0.0, so the size of the internal expression matches the size of the date.

However, in the example where NG is displayed, the size of the internal expression does not match the size of the internal expression because it is earlier than the date when the internal expression becomes 0.0.
This results in behavior that is counterintuitive.


2022-09-30 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.