x86-16 machine code, IBM PC DOS, 55 53 48 bytes
Binary:
00000000: b42a cd21 91b3 64f6 f38b c8e8 1400 8ac5 .*.!..d.........
00000010: e80f 00b0 2dcd 298a c6e8 0600 b02d cd29 ....-.)......-.)
00000020: 8ac2 d40a 0530 3050 86c4 cd29 58cd 29c3 .....00P...)X.).
Listing:
B4 2A MOV AH, 2AH ; get system date: CX=year, DH=month, DL=day
CD 21 INT 21H ; call DOS API
91 XCHG AX, CX ; move year in CX to AX (dividend)
B3 64 MOV BL, 100 ; divide by 100 to separate digits of year
F6 F3 DIV BL ; AL = first two digits, AH = last two digits
8B C8 MOV CX, AX ; save AX to CX to display last two digits later
E8 0122 CALL DISP_WORD ; display decimal value in AL
8A C5 MOV AL, CH ; move last two digits to AL
E8 0122 CALL DISP_WORD ; display decimal value in AL
B0 2D MOV AL, '-' ; date separator
CD 29 INT 29H ; fast write AL to screen
8A C6 MOV AL, DH ; move month in DH into AL for display
E8 0122 CALL DISP_WORD ; display decimal value in AL
B0 2D MOV AL, '-' ; date separator
CD 29 INT 29H ; fast write AL to screen
8A C2 MOV AL, DL ; move day into AL and display
DISP_WORD:
D4 0A AAM ; convert binary to BCD
05 3030 ADD AX, '00' ; convert BCD to ASCII char
50 PUSH AX ; save second digit for display later
86 C4 XCHG AL, AH ; convert endian, AL = first digit, AH = second digit
CD 29 INT 29H ; fast write AL to screen
58 POP AX ; restore digits
CD 29 INT 29H ; fast write AL to screen
C3 RET ; return to caller/DOS
Output
Standalone DOS program, run from the command line outputs current date to the screen.
Much of this program is converting binary values to ASCII for console output. This uses (abuses) the binary-to-BCD instruction (AAM
) to create a printable ASCII version of the output.
datetime
twice \$\endgroup\$p
in Ruby it surrounds the output in quotes, but the actual date is in the right format. Is this okay? \$\endgroup\$