Convert Internal Date into C#/VB.NET Date/Time

When working within DotNet (.NET), many times, developers need to convert MultiValue Internal Dates  into something C# or VB.NET will understand.  Many of the .NET APIs that are provided to you from your Database provider have the OCONV and ICONV functions available.

Using the OCONV and ICONV functions, you can always do the following to get an windows DateTime object:

Dim _InternalDate As String = "13548"
Dim _WinDate As Date
_WinDate = Date.Parse(session.Oconv(_InternalDate, "D4/"))

While this works well, sometimes you don’t have access to these APIs, or you may want to generate the output without the overhead of converting the information to a external format, and then parsing that format.

The DateTime object has the ability to convert an OA Date format.  The OA Date format is the number of days since December 30 1899.  So in order to convert a MultiValue internal date into a OA date, we just need to add an offset value.  The following code shows you how to do this:

Dim _InternalDate As String = "13548"
Dim _ZeroDate As New Date(1967, 12, 31)

Dim _OffsetDate As Double = _ZeroDate.ToOADate
Dim _WinDate As Date
_WinDate = DateTime.FromOADate(Integer.Parse(_InternalDate) + _OffsetDate)

Login to Read Complete Article.

Downloads:

menu
menu