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 modulo, these functions have been exposed as methods of the u2py.DynArray object.
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 BASIC Language documentation for the MV database you are using. Along with the other date codes there are other built in conversion code 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.
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 us first start with displaying the current time/date in python.
python> import timepython> 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 modulo 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.
77 4th AvenueWaltham, MA 02451 USA
Rocket Support Community
All Support Offerings
About Rocket Software
Training and Services
Forum Terms and Conditions
Contact Forum Moderator