Downloads
Article
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)
While you have to write a few more lines of code to generate the Date/Time object, it doesn’t have the overhead of the Date.Parse statement. You also do not have to worry about the date Locale issues when an external format generated for EU formats (day/month/year) vs. US formats (month/day/year).
Attached is a class you can use to convert your MultiValue dates into .NET Date/Time objects. It contains 3 functions that do the work for you:
Dim _InternalDate As String = "13548"
Dim _WinDate as Date
' Returns the MultiValue Zero Date in Date/Time format
_WinDate = mvFunctions.ZeroDate
' Converts a String Value of the Internal Date into Date/Time
_WinDate = mvFunctions.mvDateToDateTime(_InternalDate)
' Converts an Integer Value of the Internal Date into Date/Time
_WinDate = mvFunctions.mvDateToDateTime(Integer.Parse(_InternalDate))