How to Capture the Date and Time Stamp in DOS Command

Written by michael logan
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Capture the Date and Time Stamp in DOS Command
Computers with Windows also have a non-graphical user interface called DOS. (Ryan McVay/Photodisc/Getty Images)

Capturing the date and time stamp in DOS when you run a program or perform another task is easily accomplished using batch files. DOS batch files are essentially a list of commands which the operating system executes in the order they are listed. Since DOS treats nearly all devices as files, you can specify which device the output is sent to. You could send the date and time to the printer, the screen, a serial port or just store it in a file.

Skill level:

Other People Are Reading


  1. 1

    Click on the "Start" button, then click on the "Run" button. Enter the word "Command" in the text box and press the "Enter" key. A DOS window will open.

  2. 2

    Type "Edit Timestamp.bat" and press "Enter". The DOS editor program will open a file called Timestamp.bat and you will be able to enter DOS commands to be executed in the order you specify.

  3. 3

    Enter the following line and press "Enter".

    Echo |time /T>>timestamp.log

    The echo command tells DOS to direct its output. The | tells it to take its input from the following command, in this case the DOS Time function. The /T instructs the Time function to only display the time and not ask the user to input a new time. Finally, the >>timestamp.log tells the echo command where to direct the output, in this case to a file called timestamp.log.

  4. 4

    Enter the following line and press "Enter".

    Echo |date /T>>timestamp.log

    You now have a two line file, the first captures the time, the second captures the date. This command does exactly the same thing as the previous command, except it uses the DOS date function rather than the time function.

  5. 5

    Click on the File menu, then click "Save". Click "File" again, then click "Exit". You will be back at the DOS prompt.

    Type Timestamp.bat and press "Enter". The batch file will execute and return you to the DOS prompt again.

    Enter Type Timestamp.log and press "Enter". The file Timestamp.log will be printed on the screen and you will see the date and time captured on two separate lines.

Tips and warnings

  • To capture the date and time a command is given, use the two lines shown in the steps followed by the command. You can add a third line that specifies the command name or any other text you wish to enter. Just add the line "Echo This is the command time and date.>>timestamp.log" or whatever text you want to use.
  • The portion of the echo command where the output is directed to a file use >> to tell DOS to append the information to an existing file, or create a new one if the file does not exist. Using a single > will always create a new file.
  • The | character is found on the same key as the forward slash, usually located above the enter key on a standard keyboard.
  • The filename Timestamp.log is just an example, you can use any filename you choose, but it is a good idea to use an extension of .LOG, .DAT or .TXT to avoid confusion with other file extensions.
  • You can use any file name you like, but batch files must have the extension .BAT.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.