DateAdd Function Partial Hours

bmyers

New member
Joined
Jan 15, 2009
Messages
2
Programming Experience
10+
Can anybody tell me why this don't work?

Dim dt As Date

dt = DateAdd(DateInterval.Hour, 2.5, CDate("1/1/01 12:00 am"))

Label1.Text = dt


It keeps returning "1/1/2001 2:00:00 AM" instead of "1/1/2001 2:30:00 AM"

According to the help doc:

Parameters
Interval
Required. DateInterval enumeration value or String expression representing the time interval you want to add.

Number
Required. Double. Floating-point expression representing the number of intervals you want to add. Number can be positive (to get date/time values in the future) or negative (to get date/time values in the past). It can contain a fractional part when Interval specifies hours, minutes, or seconds. For other values of Interval, any fractional part of Number is ignored.

DateValue
Required. Date. An expression representing the date and time to which the interval is to be added. DateValue itself is not changed in the calling program.


Any idea what I'm missing?
 
You could just handle the minute separatly

VB.NET:
dt = DateAdd(DateInterval.Hour, 2, CDate("1/1/01 12:00 am"))
dt = DateAdd(DateInterval.Minute, 30, CDate(dt))
Label1.Text = dt

Michael
 
Use the Date method AddHours instead. There appear to be a bug with DateAdd function.
VB.NET:
Dim dt As Date = Date.Parse("1/1/01 12:00 am").AddHours(2.5)
 
Back
Top