Welcome Guest | My Membership | Login

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

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))

 

# # #          # # #          # # #

 

Related Articles

  • Convert C#/VB.NET Date/Time to Internal Date

    This Article will show you how to convert a C# or VB.NET Date/Time object into an Internal MultiValue Date. It will show you how to do it using the ICONV functions, and well as how to generate an Internal Date without using the ICONV function.

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

    This article will show how to convert a MultiValue (PICK) Internal Date into a DateTime object that you can use in C# and VB.NET. The article will cover how use the OCONV statement, as well as, how to generate the DateTime object without using the OCONV statement.

  • D3/NT RPC Client Error NE2320

    Company: TigerLogic Corporation Database: D3

    This error is generated from the D3/NT 7.x RPC Client library. D3/NT 7.x was designed to take advantage of domain RPC calls to help find the MDS server. While this made setup, installs, and other applications faster to implement, the new securities implemented in Windows sometimes interferes. Error: NE2320

  • Numeric to Alpha Translation

    Database: D3, Advanced Pick, AREV, jBase, Mentor/PRO, mv*Base, mvEnterpise, OpenInsight, OpenQM, Reality, Ultimate, UniVerse, UniData, UniVision

    The attached subroutine will convert a numeric values to their alphabetic values. The number "4" converts to "four"; "25" converts to twenty five, etc. There is also an option that will allow you to change a numeric value into an alphabetic count. For example, 4 converts to "forth", "25" converts to twenty-fifth.


Return to top