Welcome Guest | My Membership | Login

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

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)


 

# # #          # # #          # # #

 

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