ZDNet UK


Skip to Main Content

ZDNet.co.uk - Winner of Best Business Website 2007
  1. Home
  2. News
  3. Blogs
  4. Reviews
  5. Prices
  6. Resources
  7. Community
  8. My ZDNet

 

ZDNet UK RSS Feeds


IT Jobs

Desktop platforms Toolkit in association with http://ad.doubleclick.net/clk;205413468;14699245;m?http://adfarm.mediaplex.com/ad/ck/2397-58840-22058-14

Retrieve the date and time in Windows 2000 Professional batch files

Jim Boyce

Published: 26 Jun 2006 10:55 BST

  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

Sometimes it's useful to retrieve the current date and time from within a batch for a command file. For instance, say you create a batch file to perform a backup or copy operation and want the program to write the current date and time for specific actions to a log file. Or assume you create a batch file that (among other tasks) copies several folders from one location to another. Now you'll want to export the date and time the action is completed to a log file.

You have a couple of options for extracting the current date and time. One is to use the ECHO command in the batch file. You can use the %date% and %time% variables to extract the date and time, and use the > and >> redirection symbols to redirect the text to a file. The > symbol creates a file and >> appends to a file. For example, use the following command to append the date, time, and a message to a text file:

echo %date% %time% File copy operation complete. >> log.txt

Another option is to use the Now.exe tool included with the Windows 2000 Resource Kit. Now.exe extracts the current date and time and displays it on the standard output (by default, the screen). You can use redirection to direct the text to a file. The following is an example that appends the current date, time, and a message to a text file:

Now File copy operation complete. >> log.txt

To use Now.exe in a batch file, install the Windows 2000 Resource Kit and make sure the path variable points to the folder containing Now.exe (or place it in the folder from which you're executing the batch file).

  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

Did you find this article useful?
65 out of 127 people found this useful



Company/Topic Alerts

Create a new alert from the list below:



Featured Talkback

So if you upgrade to XP SP3 you can't uninstall Internet Explorer, I'm quite sure I'm having a Deja-vu feeling about MS preventing people from uninstalling Internet Explorer in other Windows products.

By: TheKLF99

Read full story:
Upgraders to XP SP3 warned over IE downgrades

Desktop Management Benchmarking

Test Your Desktop Management Systems

How good are your company's desktop management solutions? How do they compare with those of your peers?

Take two minutes to complete our new Desktop Management and Energy Consumption benchmark, and find out what issues your business needs to focus on.