qa.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
GetFileTime
   Example  Back  Contents  Index
──────────────────────────────────────────────────────────────────────────────
 
;* GetFileTime - Gets date/time for open file specified by handle.
;*
;* Shows:   DOS Function - 57h (Get or Set File Date or Time)
;*          Instructions - shl     shr
;*
;* Params:  handle - Handle of open file
;*          str - Pointer to 18-byte buffer to receive date/time
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if error
 
GetFileTime PROC \
        USES di, \
        handle:WORD, str:PTR BYTE
 
        mov     ax, 5700h               ; AH = function number
                                        ; AL = get request
        mov     bx, handle              ; BX = file handle
        int     21h                     ; Get File Date and Time
        mov     ax, 1                   ; Set error code, keep flags
        jc      exit                    ; Return code = 1 if no error
        mov     bx, cx                  ; Else save time in BX
        mov     al, bl                  ; Get low byte of time
        and     al, 00011111b           ; Mask to get 2-second incrs,
        shl     al, 1                   ;   convert to seconds
        push    ax                      ; Save seconds
        mov     cl, 5
        shr     bx, cl                  ; Shift minutes into low byte
        mov     al, bl                  ; Get new low byte
        and     al, 00111111b           ; Mask to get minutes
        push    ax                      ; Save minutes
        mov     cl, 6
        shr     bx, cl                  ; Shift hours into low byte
        push    bx                      ; Save hours
 
        mov     bl, dl                  ; Get low byte of date
        and     bl, 00011111b           ; Mask to get day in BX
        mov     cl, 5
        shr     dx, cl                  ; Shift month into low byte
        mov     al, dl                  ; Get new low byte
        and     al, 00001111b           ; Mask to get month
        mov     cl, 4
        shr     dx, cl                  ; Shift year into low byte
        add     dx, 80                  ; Year is relative to 1980
        push    dx                      ; Save year
        push    bx                      ; Save day
        push    ax                      ; Save month
 
        LoadPtr es, di, str             ; Point ES:DI to 18-byte
        mov     cx, 6                   ;   string
loop1:  pop     ax                      ; Get 6 numbers sequentially in AL
        aam                             ; Convert to unpacked BCD
        xchg    al, ah                  ; Switch bytes for word move
        or      ax, '00'                ; Make ASCII numerals
        stosw                           ; Copy to string
        mov     al, '-'                 ; Separator for date text
        cmp     cl, 4                   ; First 3 iters are for date
        jg      @F                      ; If CX=6 or 5, insert hyphen
        mov     al, ' '                 ; Separator date and time
        je      @F                      ; If CX = 4, insert hyphen
        mov     al, ':'                 ; Separator for time text
        cmp     cl, 1
        je      eloop                   ; If CX = 1, skip
@@:     stosb                           ; Copy separator to string
eloop:  loop    loop1
 
        sub     ax, ax                  ; Clear return code
        stosb                           ; Terminate string with null
exit:   ret                             ;    to make ASCIIZ
 
GetFileTime ENDP
                                    -♦-