Int 21H [2.0] Function 57H (87) Get or set file date and time

Obtains or modifies the date and time stamp in a file's directory entry.

Call with:

If getting date and time

AH = 57H

AL = 00H

BX = handle

If setting date and time

AH = 57H

AL = 01H

BX = handle

CX = time

bits 00H—04H = 2-second increments (0—29)

bits 05H—0AH = minutes (0—59)

bits 0BH—0FH = hours (0—23)

DX = date

bits 00H—04H = day (1—31)

bits 05H—08H = month (1—12)

bits 09H—0FH = year (relative to 1980)

Returns:

If function successful

Carry flag = clear

and, if called with AL = 00H

CX = time

DX = date

If function unsuccessful

Carry flag = set

AX = error code

Notes:

The file must have been previously opened or created via a successful call to Int 21H Function 3CH, 3DH, 5AH, 5BH, or 6CH.

If the 16-bit date for a file is set to zero, that file's date and time are not displayed on directory listings.

A date and time set with this function will prevail, even if the file is modified afterwards before the handle is closed.

Example:

Get the date that the file MYFILE.DAT was created or last modified, and then decompose the packed date into its constituent parts in the variables month, day, and year.

fname db 'MYFILE.DAT',0

month dw 0

day dw 0

year dw 0

.

.

.

; first open the file

mov ah,3dh ; function number

mov al,0 ; read-only mode

mov dx,seg fname ; filename address

mov ds,dx

mov dx,offset fname

int 21h ; transfer to MS-DOS

jc error ; jump if open failed

; get file date/time

mov bx,ax ; copy handle to BX

mov ah,57h ; function number

mov al,0 ; 0 = get subfunction

int 21h ; transfer to MS-DOS

jc error ; jump if function failed

mov day,dx ; decompose date

and day,01fh ; isolate day

mov cl,5

shr dx,cl

mov month,dx ; isolate month

and month,0fh

mov cl,4

shr dx,cl ; isolate year

and dx,03fh ; relative to 1980

add dx,1980 ; correct to real year

mov year,dx ; save year

; now close file,

; handle still in BX

mov ah,3eh ; function number

int 21h ; transfer to MS-DOS

jc error ; jump if close failed

.

.

.