How MS-DOS 6.22 Reads Directory Date and Time Stamps

This article explains how MS-DOS 6.22 retrieves, unpacks, and displays file and directory date and time stamps during a directory listing command like DIR. In MS-DOS 6.22, timestamps are not fetched directly from the system clock during directory enumeration; instead, they are read from dedicated bitfields stored within the 32-byte directory entry tables on FAT12 or FAT16 file systems, decoded into human-readable numbers, and formatted according to local system configuration.

The 32-Byte FAT Directory Entry

On the FAT file system used by MS-DOS 6.22, every file and subdirectory entry consists of a fixed 32-byte structure stored within the directory table. Within this block, four specific bytes determine the recorded time and date:

  • Bytes 22–23 (Offset 0x16–0x17): File modification time (16-bit word).
  • Bytes 24–25 (Offset 0x18–0x19): File modification date (16-bit word).

These values are stored in little-endian byte order, meaning the least significant byte is stored first in physical memory or disk sectors.

Bit-Level Time Format

MS-DOS packs hours, minutes, and seconds into a single 16-bit integer to conserve disk space. Because a 16-bit integer cannot store standard hours, minutes, and individual seconds simultaneously without compression, seconds are stored divided by two, giving the file system a two-second time resolution:

  • Bits 15–11 (5 bits): Hours (0–23).
  • Bits 10–5 (6 bits): Minutes (0–59).
  • Bits 4–0 (5 bits): Seconds divided by two (0–29, representing 0 to 58 seconds).

When decoding, MS-DOS isolates each value using binary bit-shifting and masking operations. The value in bits 4–0 is multiplied by two to reconstruct the approximate second count.

Bit-Level Date Format

The file creation or last-modified date uses a similar 16-bit structure, calculating the year as an offset from 1980:

  • Bits 15–9 (7 bits): Year offset from 1980 (0–127, covering the years 1980 to 2107).
  • Bits 8–5 (4 bits): Month of the year (1–12).
  • Bits 4–0 (5 bits): Day of the month (1–31).

To display the year, MS-DOS adds 1980 to the integer value found in bits 15 through 9.

Execution via DOS API and Display

When a user executes the DIR command in COMMAND.COM, the shell calls MS-DOS Kernel API functions—specifically Interrupt 21h, Function 4Eh (Find First File) and Function 4Fh (Find Next File).

  1. Reading from Disk: The kernel locates the directory sector on disk, parses the 32-byte records, and loads matching file entries into a memory buffer known as the Disk Transfer Area (DTA).
  2. Unpacking Values: COMMAND.COM reads the raw 16-bit time and date words from the DTA, applies bitwise logical AND masks along with shift operations, and calculates the standard integer values for year, month, day, hour, and minute.
  3. Localization and Display: Before printing the output to the console, MS-DOS checks the country conventions defined in CONFIG.SYS (via COUNTRY.SYS). This determines whether the output prints in the United States format (MM-DD-YY), European format (DD-MM-YY), or Japanese format (YY-MM-DD), as well as whether to display the time using a 12-hour (am/pm) or 24-hour clock.