Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Date into a dos environment variable

Posted on 1999-07-29
Medium Priority
Last Modified: 2013-12-29
How do I get the current date into a dos environment variable?
Something like "set curdate=date /t"

Question by:tims
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

czpczp earned 200 total points
ID: 1803848
Hi Tim.

The following batch files creates an environment variable with the name of "date" with the current date.

Use this batch file for any DOS, Windows 3.x, and Windows 9.x machine:

rem-------------------------  GetDate.BAT  --------------------------------
@echo off
echo.|date|find "Current" >cu##ent.bat
echo set date=%%4> current.bat
call cu##ent.bat
del cu??ent.bat > nul
rem-------------------------  GetDate.BAT  --------------------------------

If you have to run this on any Windows NT machine, then use this one instead:

rem-------------------------  GetDate.BAT  --------------------------------
@echo off
echo.|date|find "current" >t#e.bat
echo set date=%%5> the.bat
call t#e.bat
del t?e.bat > nul
rem-------------------------  GetDate.BAT  --------------------------------

After running the batch file, you'll have an environment variable with the name "date" holding the current date.

To test, at a DOS prompt type SET or SET DATE or ECHO %DATE%.

Best regards, Steve.

Author Comment

ID: 1803849

Thanks Steve.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question