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> itest = test.iconv(“D”)
Since the itest variable now has a date in internal format, you can use a different conversion code to get other display formats.
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.
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.
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.