DateSerial Method - Date.ToOADate Method

  • Thread starter Thread starter Kenny
  • Start date Start date
K

Kenny

I am having issues with the "Date.ToOADate" method in
VB .NET. I understand that in VB6 the function DateSerial
gives an internal representation of the date.

When I use the DateSerial method in VB .Net, dragging the
mouse over to the statement, VB .NET reports the following
"Conversion from 'Date' to "Double' requires calling
the 'Date.ToOAdate' method.

When I tyoe this method in, the syntax checker undelines
the method and will not compile. The
method 'Date.FromOADate' works.

Can someone please shed some light.
 
Kenny,
What are you attempting to do?

DateSerial is used to return a Date value in both VB6 & VB.NET, not the
internal representation of a date.

In both VB6 & VB.NET you would use DateSerial like this:

Dim d As Date
d = DateSerial(2003, 12, 1)

Remember that in VB.NET that the internal representation of a date has
changed from the VB6 internal representation of a date. VB6 (COM) defined a
date based on a Double, VB.NET (.NET) defines it based on an Long (64 bit
integer).

Hence the need to call Date.ToOADate.

Dim d As Date
Dim f as Double
d = DateSerial(2003, 12, 1)

f = d.ToOADate()

d = Date.FromOADate(f)

Hope this helps
Jay
 
Back
Top