Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wanted: help writing CMD.EXE script using current date 1

Status
Not open for further replies.

heintze

Programmer
Nov 19, 2005
61
US
I have some automated procedures that daily create a new directory. Everyday, I have to edit a bat file (that creates environment variables) to use the current date. In cygwin bash I would use
export OCAPROOT=/cygdrive/c/XYZ/daily_build`date +"YYYYMMDD"`

How would I use this in CMD.EXE?

Is this an appropriate question for this forum? If not, what is a better forum?

Thanks,
Siegfried
 
Code:
Set WshShell = CreateObject("Wscript.Shell")
strDailyBuild = Year(Date) & Month(Date) & Day(Date)
WshShell.Run ("CMD.EXE /K Set OCAPROOT= \cygdrive\c\XYZ\daily_build" & strDailyBuild)

The problem with doing this is that as soon as the VM is closed the variable goes away.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Sorry, I'm not familiar with *nix style scripting...

But current dates in cmd.exe are very easy.

It would help if you posted the script or that part you have to edit so I could clearly see what you're trying to do...

But, lacking that, I'll say this assuming you are using a US Standard date format, then:

Code:
%date:~-4%%date:~4,2%%date:~7,2%
is equal to
YYYYMMDD

And if you preferred using your own variables, then, for example:
Set YYYY=%date:~-4%
Set MM=%date:~4,2%
Set DD=%date:~7,2%

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top