The Date Data Type

DATE indicates that a value consists of eight digits representing a date in the form YYYYMMDD. For example, 19990821 is August 21, 1999.

Note: If you are using Zim in conjunction with a third-party SQL database engine, the format of dates can differ from that described here. In such cases, your code must avoid making any assumptions about the format of date fields.

Dates and numbers can be freely interchanged. When a number is converted to a date, the number is assumed to adhere to the YYYYMMDD format, so that dividing the number by 10,000 (for example) yields the year. You can subtract one date from another to find the number of days between them, or you can add or subtract a number of days to or from a date to generate another date (i.e., date arithmetic).

The software provides a number of functions to manipulate DATE values. These functions ($year, $ monthname, $ addmonths, $weekday, etc) are described in the Language Reference book of this online help.

Date Data Type Characteristics

Data TypeDecimalsValid RangeStorage Occupied
DATENoneJanuary 1, 0001 to December 31, 9999Eight bytes

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

How To Use Data Types

The following are the character data types:

  • alpha

  • varalpha

  • char

  • varchar

The following are the numeric data types:

  • int

  • longint

  • vastint

  • numeric

The following is the other data type:

  • date

Alpha Data Type

A character string of fixed length (uses a pre-defined amount of storage space). Pads with trailing blanks if necessary. Case insensitive in sorts, compares, and so on, but case is stored and is apparent on display.

Varalpha Data Type

A character string of variable length (uses only as much storage space as data requires). Ignores trailing blanks if entered. Case insensitive in sorts, compares, and so on, but case is stored and is apparent on display.

Char Data Type

A character string of fixed length (uses a pre-defined amount of storage space). Pads with trailing blanks if necessary. Case sensitive in sorts, compares, and so on.

Varchar Data Type

A character string of variable length (uses only as much storage space as data requires). Ignores trailing blanks if entered. Case sensitive in sorts, compares, and so on.

Int Data Type

A numeric value occupying two bytes of storage space. Can contain any number of decimal places, but digit value (ignoring decimal places) must fall between -32768 and 32767.

Longint Data Type

A numeric value occupying four bytes of storage space. Can contain any number of decimal places, but digit value (ignoring decimal places) must fall between -2147483648 and 2147483647.

Vastint Data Type

A numeric value occupying eight bytes of storage space. Can contain any number of decimal places and up to fifteen significant digits (ignoring decimal places).

Numeric Data Type

A number stored in character form. Can include a leading sign (+, -), or an embedded decimal point, or both. Can include spaces between the sign and the first digit, but not between digits.

Date Data Type

A date value occupying eight bytes of storage space. On display, contains eight digits in the form YYYYMMDD. Dates and numbers are freely interchangeable, and date arithmetic is available.

Implicit Data Types of Literals

Literals express values outside of pre-defined application objects. Because literals have no definition in the Object Dictionary, the software assumes a data type for each literal. This implicit data type is determined based on the characters contained in the value, and on whether or not the value is enclosed in quotation marks.

Literals that are enclosed in quotation marks, or that are unquoted but contain letters, are assumed to be character strings. Character strings are always implicitly CHAR.

Unquoted literal values that contain only digits, or digits and a decimal point are assumed to be numbers. Number literals are always implicitly VASTINT.

Constants (literals defined as objects, with names, in the Object Dictionary) can be assigned either the CHAR or VASTINT data type. No other type is permitted. The assigned data type overrides the data type implicit in the value of the constant.

Examples of Implicit Data Types

1234Is implicitly VASTINT.
abcdIs implicitly CHAR.
2.6Is implicitly VASTINT.
a1b2Is implicitly CHAR.
‘1234’Is implicitly CHAR.
‘ abcd’Is implicitly CHAR.
‘-2.6’Is implicitly CHAR.
‘a1b1’Is implicitly CHAR.

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Data Types and the Use of Database Indexes

The software automatically determines if it can use indexes when it looks for records in the database. If the software cannot use an available index, each record in the record-containing objects must be scanned (a potentially slower process).

In some cases, the software cannot use an available index if the data type of the indexed field and the data type of the comparison value are incompatible.

Data Type Compatibility in Indexed Database Searches

Data Type of Indexed Field

Required Data Type of Comparison Value (for index to be used)

CHAR, VARCHAR

CHAR, VARCHAR

ALPHA, VARALPHA

CHAR, VARCHAR, ALPHA, VARALPHA

Any number data type, DATE

Any data type

Example

If you enter the command

find Employees where EmpNum = 156

and EmpNum is an Indexed field of a character type, you are asking to compare the number 156 to a character field.

In this case, the software does not use the available index, because to do so would produce an incorrect result. The index is sorted internally, based on character comparisons. The literal 156 is implicitly a VASTINT number and cannot be effectively compared to character values.

Instead, the software performs the FIND by checking the 156 against the individual values of EmpNum. Speed of execution is slower than if the index could be used.

To ensure that the index is used, modify the command to read

find Employees where EmpNum = ‘156’

In this case, the literal, because it is enclosed in quotation marks, is implicitly a character data type (CHAR), and can be compared to the indexed EmpNum values, which are explicitly character type.

Data Types and Storage of Values

ALPHA/CHAR and VARALPHA/ VARCHAR Values

If an ALPHA or CHAR object is assigned the value abc///// (with five trailing blanks), it is stored as abc///// (fixed length value).

If a VARALPHA or VARCHAR object is assigned the value abc/////, it is stored as abc without any trailing blanks, but with an indicator that gives the length of the value (variable length value).

Maximum Lenth for ALPHA/CHAR and VARALPHA/VARCHAR

 

ALPHACHARVARAPLHAVARCHAR
32767 bytes32767 bytes32767 bytes32767 bytes

INT and LONGINT Values

INT, LONGINT and VASTINT values are stored “without decimals”. Actually, the decimal information is stored separately.

The “non-decimal” value (value of the significant digits) must fall within the range of the applicable data type.

Examples – INT Values

ValueSignificant DigitsNumber of DecimalsValid Maximum/Minimum Values
123.4123413276.7 / -3276.8
12.3412342327.67 / -327.68
12.341234332.767 / -32.768
0.01234123450.32767 / -0.32768

Examples – LONGINT Values

ValueSignificant DigitsNumber of DecimalsValid Maximum/Minimum Values
1.23456123456521474.83647 / -21474.83647
1234.56123456221474836.47 / -21474836.47

See Also

About Conditional Expressions

Conversion Between Data Types

Data Types and the Use of Database Indexes

How To Use Data Types

Conversion Between Data Types

Zim performs conversions and operations between data types in a different manner than other application development languages. The rules for conversions are embedded in Zim itself, and when performing conversions or comparisons, these rules govern how the different data types are handled.

Implicit Conversions

In general, when you write an expression, you can use objects or literals of any data type, in any combination. However, when the software encounters an expression containing values with mixed data types or a data type incompatible with the requirements of the expression, it applies a number of rules for converting the data types should conversion be necessary.

Character-to-character Comparisons

  1. When values are being compared, VARALPHA and VARCHAR values are treated as if they were ALPHA and CHAR values, respectively.
  2. When two values of type ALPHA are being compared, an ALPHA-type (case insensitive) comparison is performed.
  3. When two values of type CHAR are being compared, a CHAR-type (case sensitive) comparison is performed.
  4. When two values are being compared, one of type CHAR and one of type ALPHA, an ALPHA-type (case insensitive) comparison is performed.

Character-to-number Conversions

  1. When two values – only one of which is a number type – are compared or are processed in an arithmetic operation, the value that is not a number type is converted to a number and a numeric comparison or operation is performed.

Number-to-character Conversions

  1. If a number (type INT, LONGINT, VASTINT) must be converted to a character string for use by a command or function (e.g., to be output by the LIST command or processed by $ substring), the number is converted and right-justified, always producing a result string long enough to hold the largest possible value for that data type (8 characters for INT; 12 characters for LONGINT; 17 characters for VASTINT).
  2. Number literals implicitly take the data type VASTINT and assume a number of decimal places equal to the number that actually appear in the literal. If the software has to convert a number literal to a character string for use by a command or function, it becomes a character string 17 characters long, as indicated in Rule 6.

Date Comparisons

  1. When two values are being compared, only one of which is type DATE, the other value is converted to DATE (if possible) and a DATE comparison is performed.
  2. If a number is converted to a date, it is assumed to be in a YYYYMMDD form (e.g., 19991122 is November 22, 1999).

Arithmetic Operations Involving Dates

  1. When an arithmetic operation is being performed on two values, at least one of which is type DATE, the operation is carried out as summarized below:
val1 + val2

If only one value is type DATE, the other is converted to a number and added (as a number of days) to the date.
If both values are type DATE, a normal arithmetic operation is performed and the result is treated as a number.

val1 – val2

If both values are type DATE, the dates are subtracted to yield the number of days between the two dates.
If val1 is type DATE and val2 is not, val2 is converted to a number (if necessary) and is subtracted (as a number of days) from the date.
If val2 is of type DATE and val1 is not, both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

val1*val2
val1/val2
val1^val2

Both values are converted to numbers (if necessary) and a normal arithmetic operation is performed.

Date-to-character Conversions

  1. If a DATE value must be converted to a character string, it becomes a string eight characters in length.

Explicit conversion Using Software Functions

Although values are implicitly converted from one data type to another as required, the software provides a number of functions that forcibly convert values from one data type to another.

The conversion functions are $ toalpha, $ tocharacter, $ todate and $ tonumber.

 

See Also

=, , >, >= (Condition)

About Conditional Expressions

Data Types and Storage of Values

Data Types and the Use of Database Indexes

How To Use Data Types

Opening Existing Objects

Opening Objects through the Database Tab Page.

✓   In Zim IDE, the Database Tab Page can be accessed by clicking the Database Tab at the bottom-left of the screen or the Database Tab Page Icon on the View Menu bar.

✓   The Database Tab Page will become visible on the left side of the Zim IDE window.

✓   Browse the objects in the tree view and double-click on the object you wish to open and edit in the GUI Designer.

Designing Form Fields

Note: when painting displays you must add one or more forms to the display first before adding fields.  Forms are the only object that can be directly added to a display.

✓   From the toolbox tab, select the type of object that you wish to add to the current form:

✓   Using the mouse, draw the outline of the field on the form.  Start in the top left position where the field is to be placed and click on the left mouse button.  While holding the mouse button down, position the mouse cursor at the bottom right location of the new field and then release the mouse button.

✓   The field has now been added to the form with a default set of properties.  You may now navigate to the properties tab on the right side of the painter window and change any of the field’s properties.

en_CAEnglish