Link to home
Start Free TrialLog in
Avatar of tech-
tech-

asked on

VB Script or Batch File to insert date

I need to setup a script that I will execute through Windows Scheduler on a daily basis.

I currently run this command on our Windows 2008 Server:
D:\>robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup04112010.txt

I need the date to automatically 04112010 to update when the script is run.  I don't care if it is a VB script or a simple batch file, but it just needs to work so I can automate this process.

Please let me know and Thanks!!!
Avatar of TakedaT
TakedaT
Flag of United States of America image

Like this?
for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do (
	set today=%%b%%c%%d
)

echo.D:\>robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup\%today%.txt

Open in new window

Give this a try:
tdate = Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & Year
RunStr = "D:\robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" & tdate & ".txt"
Set wshell = CreateObject("WScript.Shell")
wshell.Run(RunStr)

Open in new window

Execute the below listed vbscript (.vbs) in your task scheduler
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" &Date &".txt",0,True

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Justin Ellenbecker
Justin Ellenbecker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Depending on the configure format ;) For me it's . (dot)
Below a formated one :P
Set objShell = CreateObject("Wscript.Shell") 
objShell.Run "robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" &Replace(Date,"/","") &".txt",0,True

Open in new window

Yeah I went with extra variable to allow for MMDDYYYY so on months like this its not 4132010 it will always sort well then. Either way it will do what he wants I jsut noticed his current formatting.
Avatar of tech-
tech-

ASKER

Thanks!!!