If anyone knows what the specifications are for adding dates in VBS, please let me know.
' (1) x = #10:10:10# MsgBox CStr(x + x) ' 20:20:20 ' (2) x = #1899-12-29 00:00:01# y = #1899-12-30 00:00:01# ' #00:00:01#と同じ MsgBox CStr(x + y) ' 1899/12/29 MsgBox CStr(y + x) ' 同上 ' (3) x = #1899-12-29 00:00:01# MsgBox CStr(x + x) ' 1899/12/28 0:00:02 ' (4) x = #1899-12-29 00:00:01# y = #1899-12-31 00:00:01# MsgBox CStr(x + y) ' 0:00:00
(1) would be good. It can be calculated by
x + (y - 基準日) .
(2) indicates that the calculation method is switched when only one of the additions is before the base date of 1899/12/30 00:00:00. Consider the base date as "straddling",
x < 基準日 && 基準日 <= y then
x - (y - 基準日) ,
y < 基準日 && 基準日 <= x if
y - (x - 基準日) It seems that it is the
y - (x - 基準日) .
(3) shows that the calculation method is still switched even if both of the additions are before the base date. It seems that the calculation method is the same as (1).
(4) shows that the flow of time before the reference date and the flow of time after the reference date are different. The result is 0:00:00, even though the amount of distance from the base date differs between x (-23:59:59) and y (+24: 00: 01). I don't know the conditions for matching (2) with this result (expected 30 days is treated specially …? Unverified).
In addition to this, I am worried that conditions other than those listed above may be involved. Please let me know if you know that "there are specifications here" and "there are such conditions". Please.
Addendum: I'm not talking about using DateAdd because I need to port code that uses existing additions without changing its behavior.
I'm not very familiar with VBS, so the subtle terms may be wrong … This can be seen by looking at the internal representation of Date through
WScript.Echo CDbl(#1899-12-29 00:00:00#) WScript.Echo CDbl(#1899-12-29 12:00:00#) WScript.Echo CDbl(#1899-12-30 00:00:00#) WScript.Echo CDbl(#1899-12-30 12:00:00#) WScript.Echo CDbl(#1899-12-31 00:00:00#)
The area around the reference time is converted to a
double at 12-hour intervals and displayed. Result is:
-1 -1.5 0 0.5 1
#1899-12-29 12:00:00# that the value of
#1899-12-29 00:00:00# is smaller than the previous # 1899-12-29 00:00:00 #.
The internal representation of Date is
<基準日からの日数>.<その日の 00:00:00 からの時間> , that is,
- The integer part is the number of days from the base date (it becomes a negative number before the base date)
- The decimal point is the time from 00:00:00 of the day (equivalent to 24 hours = 1.0)
It is like that. Therefore, the small size of the internal representation before the base date and the front and back as the date and time do not match.
Expressing the date in question in an internal representation:
x = #1899-12-29 00:00:01#is
x = -1.00001157407407That is, the first second of the base date-1
y = #1899-12-31 00:00:01#is
y = 1.00001157407407That is, the first second of the base date +1
If you forcibly add Date with
+ , add it with this internal representation, and then return it to Date. So
x + y is
0 , which is the above result.