Date.exe

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 http://unxutils.sourceforge.net. 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.

Please or Register to post comments.

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.