Dates in UniVerse Basic
So dates we tend to use them quite often, especially in financial or accounting transactions. Having sound knowledge of how to format or display them will make life easier.
I'll go through an example of how dates operate in this environment.
Internally in UniVerse Basic a date is a numeric character of 5 digits long. So if I took today's date which is 13/02/2017 it would be equivalent of 17942 as an internal format.
To get the internal format you'd have a function like this:
INTERNAL.DTE = ICONV(13/02/2017, 'D4/DMY[2,2,4]')
Variable internal date will have the value 17942. Note that there are two parameters in the function. The first one is the date and the second the format. Let's break down that format to make it a bit more clear.
D4/ - The 'D' tells us we're working with a date. The numeric '4' tells us the number of digits for the year input. Now the slash character tells us which separator we're using.
DMY[2,2,4] - 'D' would represent the day, 'M' the month and 'Y' the year. The numeric characters states the format for the day, month and year. So '2' will represent a day in the calendar month, e.g. 03, 25, 11. The next '2' will represent the month, e.g. 01 up until 12. The '4' will be for the year, e.g. 1987, 2017.
The same logic can be used when converting an external date to internal format.
EXTERNAL.DTE = OCONV(11111,'D4/DMY[2,2,4]')
This will give you a date of 02/06/1998. If it was 11112, the date would be 03/06/1998. One day on from the previous date.If you would have changed the seperator to - you would end up with a date like 02-06-1998.
I'll go through an example of how dates operate in this environment.
Internally in UniVerse Basic a date is a numeric character of 5 digits long. So if I took today's date which is 13/02/2017 it would be equivalent of 17942 as an internal format.
To get the internal format you'd have a function like this:
INTERNAL.DTE = ICONV(13/02/2017, 'D4/DMY[2,2,4]')
Variable internal date will have the value 17942. Note that there are two parameters in the function. The first one is the date and the second the format. Let's break down that format to make it a bit more clear.
D4/ - The 'D' tells us we're working with a date. The numeric '4' tells us the number of digits for the year input. Now the slash character tells us which separator we're using.
DMY[2,2,4] - 'D' would represent the day, 'M' the month and 'Y' the year. The numeric characters states the format for the day, month and year. So '2' will represent a day in the calendar month, e.g. 03, 25, 11. The next '2' will represent the month, e.g. 01 up until 12. The '4' will be for the year, e.g. 1987, 2017.
The same logic can be used when converting an external date to internal format.
EXTERNAL.DTE = OCONV(11111,'D4/DMY[2,2,4]')
This will give you a date of 02/06/1998. If it was 11112, the date would be 03/06/1998. One day on from the previous date.If you would have changed the seperator to - you would end up with a date like 02-06-1998.
Comments
Post a Comment