Windows Tip Sheet

Does Anybody Really Know What Time It Is?

Lazy or just efficient? How to display the clock at the command prompt.

If you've been following my Tip Sheet columns, you know I am a big fan of the command prompt and practically live in it. I like to keep a pretty clean desktop, which means I auto-hide the Windows Start Bar. An unfortunate downside is that this also hides my clock. I don't have a clock in my office and when I'm head-down working, I don't want take my eyes off the monitor to glance at my watch. That's assuming I put it on. Plus, I sometimes forget what day it is, especially when there are holidays.

This week's tip won't change the world or solve some mission-critical problem. It falls in the category of "Jeez, that's kind of cool. Let me try."

I've modified my prompts, both in CMD and PowerShell so that they always display the current time and date. The time and date display isn't a clock per se. The time is updated every time I press Enter. It looks like this:

[Wed 01/17/2007 21:11:02.12] C:\>

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at [email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

To modify my prompt in the CMD shell I simply use the command:

set prompt=[$D $T] $P$G

The $D attribute displays the date, $T the time, $P the current directory and $G the right angle bracket. I enclosed the date and time in square brackets purely for cosmetic purposes.

Since I don't want to enter this command every time I open a command shell (plus, I have some shell customizations such as my DOSKEY macros), I've created a batch file that includes the prompt command. I then entered the path to the batch file in the AutoRun key under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor

If you don't have the key, you can create it. It is type REG_SZ.

Now, all my CMD shells show me the current date and time and all I have to do is look straight ahead and keep working.

Next week, I'll show you how to handle this with PowerShell.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025