• Please review our updated Terms and Rules here

Short-form alternative to NOW in an MS-DOS 3.3 batch file?

charnitz

Experienced Member
Joined
Nov 17, 2020
Messages
55
Location
North America
DATE and TIME prompt for date and time entry and do not have flags to bypass the prompt.

NOW writes out a long sentence like:

It is now February 16 2021, 1:23:32.06 .​

Can we get a condensed datetime stamp like this?

2021-02-16 01:23​
 
I'm not very familiarized with that NOW command. In fact, I couldn't find it on my DOS 3.3 distribution. Nevertheless, I guess it must not be very flexible. In such cases, I prefer to create my own commands, giving me exactly what I need.

I just made a quick and dirty C program that gives what you ask for:

Code:
#include <stdio.h>

void main ()
{
    int year;
    char month,day;
    char hour,minute;
    
    asm {
        mov     ah,2Ah
        int     21h
    }

    year = _CX;
    month = _DH;
    day = _DL;

    asm {
        mov     ah,2Ch
        int     21h
    }

    hour = _CH;
    minute = _CL;

    printf ("%d-%d-%d %d:%d",year, month, day, hour, minute);

}

Of course, it may be improved. For example, with a little more work it could add a zero before the one digit numbers.

If it were translated into pure assembler, you could save several kb, but it would be a little more complicated to code as string management is not as easy in assembly as it is in high level languages. Said that, the good part is the code indeed works. It must be compiled on Turbo/Borland C, I think it would do well on any version, I used TC++ 1.1. It may compile on other C versions (MS, Watcom, etc.) but it probably would need some arrangements.
 
Another option would be to make use of the PROMPT command. $d and $t provide a shorter date and time stamp. So a complete PROMPT might look like
PROMPT $d$t$_$p$g
which would give a result of
Wed 02-17-2021 7:56:20.81
C:\>

I prefer the prompt with full path and the greater than sign but you don't have to. Making a batch file to switch the PROMPT to include date and time and then switch back to the preferred standard prompt is another option if you don't want to see the updated date and time on every entry.

May have different formatting with different versions of DOS. PCJS shows MS-DOS 3.3 using dashes in the date.
 
I just expanded my program to add a zero before the one digit numbers. It was easier than I thought... ;)

Code:
#include <stdio.h>

void main ()
{
    int year;
    char month,day;
    char hour,minute;
    
    asm {
        mov     ah,2Ah
        int     21h
    }

    year = _CX;
    month = _DH;
    day = _DL;

    asm {
        mov     ah,2Ch
        int     21h
    }

    hour = _CH;
    minute = _CL;

    printf ("%d-%02d-%02d %02d:%02d",year, month, day, hour, minute);

}
 
Back
Top