In "An Easier Way to Name Log Files with the Current Date and Time" (September 2003, InstantDoc ID 39695), Richard Gutter suggests using Windows NT's Date and Time commands to obtain a log file's current date and timestamp. However, these commands' output is limited. The date/t and time/t commands' output is time-zone dependent, and the %date% and %time% variables' format is fixed. In addition, Richard's example illustrates that using the Date and Time commands to build filenames or log-file timestamps requires additional awkward substring extraction and subsequent assembly.

A more powerful and flexible solution is UNIX's date.exe. You can download date.exe's Windows version at Listing 1 shows an example of using date.exe to create log files and format log-file entries. This command offers detailed output control. As Table 1 shows, you can put a date or time item anywhere you want in the output string. Note that in .bat files, you need to use double percent signs (%%) rather than a single percent sign. You might need to use the fully qualified path and name to call date.exe to prevent calling the internal Date command.

For more information about date.exe, open a command prompt and enter

<path>\date.exe -help

The output displays date.exe's supported parameters.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.