HMIDNT: Setting the Time Portion of a Date-Time Value to Midnight

How to:

The HMIDNT function changes the time portion of a date-time value to midnight (all zeros by default). This allows you to compare a date field with a date-time field.


Top of page

x
Syntax: How to Set the Time Portion of a Date-Time Value to Midnight
HMIDNT(datetime, length, output)

where:

datetime

Date-time

Is the date-time value whose time is to be set to midnight, the name of a date-time field that contains the value, or an expression that returns the value.

length

Integer

Is the length of the returned date-time value. Valid values are:

8 indicates a time value that includes milliseconds.

10 indicates a time value that includes microseconds.

12 indicates a time value that includes nanoseconds.

output

Date-time

Is the date-time return value whose time is set to midnight and whose date is copied from timestamp. Is the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be in date-time format (data type H).



Example: Setting the Time to Midnight (Reporting)

HMIDNT sets the time portion of the TRANSDATE field to midnight first in the 24-hour system and then in the 12-hour system:

TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
TRANSDATE_MID_24/HYYMDS  = HMIDNT(TRANSDATE, 8, 'HYYMDS');
TRANSDATE_MID_12/HYYMDSA = HMIDNT(TRANSDATE, 8, 'HYYMDSA');
WHERE DATE EQ 2000;
END

The output is:

CUSTID  DATE-TIME         TRANSDATE_MID_24     TRANSDATE_MID_12 
------  ---------         ----------------     ---------------- 
1118    2000/06/26 05:45  2000/06/26 00:00:00  2000/06/26 12:00:00AM
1237    2000/02/05 03:30  2000/02/05 00:00:00  2000/02/05 12:00:00AM


Example: Setting the Time to Midnight (Maintain)

HMIDNT sets the time portion of DT1 to midnight in both the 24- and 12-hour systems:

MAINTAIN FILE DATETIME
FOR 1 NEXT ID INTO STK;
COMPUTE
DT_MID_24/HYYMDS = HMIDNT(STK(1).DT1, 8, DT_MID_24);
DT_MID_12/HYYMDSA= HMIDNT(STK(1).DT1, 8, DT_MID_12);
TYPE "STK(1).DT1 = "STK(1).DT1;
TYPE "DT_MID_24 = <DT_MID_24";
TYPE "DT_MID_12 = <DT_MID_12";
END

Information Builders