Maintain and Date-Time Fields
by Mark Derwin
Maintain makes it very easy to read, manipulate and when you need to write date-time fields. You can perform calculations and transformations from one date format to another. Here are some easy techniques to accomplish this.
To populate a date-time field, use the HGETC subroutine. The syntax of this routine is as follows:
Compute Var/format = HGETC(length, outfield);
The format must be a valid date-time format and the outfield must be the name of the variable. You cannot specify the format. A simple example is like this:
MAINTAIN
Compute DT1/HYYMDm = HGETC(26, DT1);
Type “DT1 = <<DT1”
END
This yields the following:
DT1 = 2007/03/02 10:19:34.063000
If you try to compute a date-time field to a standard date field, you get an error. You cannot just equate one to the other. When doing most calculations, Maintain handles the transformation for you. You never need the EDIT command. You can compute an integer to an alpha or a decimal to a float without any issues. However, if you want to extract just the date from a date-time expression, use the HDATE function.
The syntax for the HDATE function is as follows:
Compute Var/format = HDATE(infield, outfield);
Using my example from before we would have:
MAINTAIN
Compute DT1/HYYMDm = HGETC(26, DT1);
Compute DT2/YYMD = HDATE(DT1, DT2);
Type “DT1 = <<DT1”
Type “DT2 = <<DT2”
END
And that yields the following:
DT1 = 2007/03/02 10:19:34.063000
DT2 = 2007/03/02
While you cannot compute a date-time field to a standard date, the opposite is allowed. If you have a standard date, you can equate it to a date-time field. The time portion will just contain all zeroes.
Maintain can take advantage of all of the date-time routines available to reporting. We can use HDIFF to get the differences between two date-time fields, HADD to increment the values, and many others. Another nice thing is when you use the pop-up JavaScript calendar, and the field is date-time, fields are presented to enter hour, minutes and seconds. Just remember to always use the name of the outfield instead of the field’s format.

