DEALING WITH INTERNAL AND DISPLAY FORMAT DATA IN YOUR MV DATABASE WITH PYTHON

Part 1 of 3

By storing your data in internal format in your MV database, you can easily convert the data to a desired display format. One of the most common uses for conversion codes is dealing with dates. In MV, the internal representation of the date is an integer.

For example the internal format for “04 Dec 2014” is 17140.  Those familiar with U2 BASIC know they can get the internal format to the display date format by using the OCONV function.

I.e   PRINT OCONV(17140, "D")

The ‘D’ is the Date conversion code and it is used with both the ICONV function as well as the OCONV function.

With the introduction of the u2py module, these functions have been exposed as methods of the u2py.DynArray object.

python> test = u2py.DynArray(“04 Dec 2014”)
python> itest =  test.iconv(“D”)
python> itest
<u2py.DynArray value=b’17140′>

Since the itest variable now has a date in internal format, you can use a different conversion code to get other display formats.

python> itest.oconv(“D4/”)
<u2py.DynArray value=b’12/04/2014′>

For a complete list of Date conversion codes please see the BASIC Language documentation for the MV database you are using.  Along with the other date codes, there are other built in conversion codes in the MV databases.

One that tends to go along with date is time. The internal format of time is the number of seconds since midnight.

python> internalTime = u2py.DynArray(“16200”)
python> print(internalTime.oconv(“MTHS”))
04:30:00AM
Up to this point I have been hard coding the internal or external values used to pass to the u2py methods. The following example shows how you can use the Python time module with the u2py module to work with dates.

Let’s first start with displaying the current time/date in Python.

python> import time
python> now = time.time()
python> theLocalTime = time.localtime(now)
python> print( time.asctime(theLocalTime) )
Fri Dec  5 07:30:07 2014

While this produces the date and time, it will not convert directly into U2 without modifying the display format to something handled by the U2 iconv method.

python> u2DisplayTime = u2py.DynArray(time.strftime(“%d %b %Y”, theLocalTime))
python> u2DisplayDate.iconv(“D”)
<u2py.DynArray value=b’17141′>

Please take some time and work with both the Python time module as well as the U2 oconv and iconv methods. In my next post, I will show how to access the Python time module from U2 BASIC.

Michael Rajkowski

Michael Rajkowski 12 Posts

As a member of the Rocket MultiValue Support organization, Michael has worked with MultiValue for over 25 years in numerous professional roles. He is especially fascinated with the areas of MultiValue that intersect with other technologies. He recently moved to Irvine, where he can not only expand his MultiValue expertise to include the Rocket D3 product family, but also where he, his wife and son can enjoy being closer to Disneyland.

1 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *