Downloads
Article
When developing DotNet (.NET) applications, Date/Time objects are commonly used within business applications. While the DateTime object give you a lot of functionality, it doesn’t have a native function to convert it back into a MultiValue Internal Date.
Since we always save dates in a compressed Internal formats within the MultiValue database, we have to convert the DateTime object into something we can store.
The easiest way to do this is to use the ICONV statement in the APIs provided by the database providers.
Dim _InternalDate As String
Dim _WinDate As Date = Now
_InternalDate = session.Iconv(_WinDate.ToShortDateString, "D")
While this is straight forward, there is a lot of additional override that may not be required. You can easily convert your Date/Time object without using ICONV statement.
To do this, we take advantage of the OA Date format provided by by the DateTime object. The OA Date format is the number of days before or after midnight, December 30 1899. This is very similar to the MultiValve Internal date format, except for what is considered the Zero Date.
Using a little math, you can generate the MultiValue Internal date:
Dim _InternalDate as String
Dim _WinDate as Date = New
Dim _Days as Double
Dim _ZeroDate As New Date(1967, 12, 31)
_Days = _WinDate.ToOADate - _ZeroDate.ToOADate
_InternalDate = Math.Truncate(_Days).ToString
Since the OA Date also included a Time component saved as a decimal value, you have to strip that off in order to get the Internal Date value by itself.
When working with Locale formatting, you sometimes have issues with the ToShortDateString generating an EU formats (day/month/year) when you want a US formats (month/day/year), or vise-versa. This can cause the ICONV functions to generate the wrong date. While the database providers do a good job of sensing the different formats, it is not always 100%.
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
Dim _WinDate as Date = Now
' Returns the current Date as an Internal Date
_InternalDate = mvFunctions.mvDateInternal
' Converts a Date/Time Object into an Internal Date
_InternalDate = mvFunctions.mvDateInternal(_WinDate)