date and time stamp batch files

I have this script in a batch file:

The robocopy works fine but thye namedate just does not work:

robocopy \\trams-pc\tramsDatabase \\dell-server\svrbackups\tramsDB
NAMEDATE /X /Q /Y "\\dell-server\svrbackups\tramsDB\PERFECT_TRAVELDB.IB"

Can someone please suggest how to add a time and date stamp to the file after it has been copied
doctorbillTechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Another utility worth trying is DateX at http://www.westmesatech.com/sst.html

for /f %%a in ('DateX -f YYYY_MM_DD_HH_MM_SS') do (set TimeStamp=%a)
for %%a in ("\\dell-server\svrbackups\tramsDB\PERFECT_TRAVELDB.IB") do (echo ren %%a %~na_%TimeStamp%%~xa)

Open in new window


If you want a pure .bat:

DateTime-YYMMDDHHMMSSUU.bat
@ECHO OFF
set DateTimeNow=
set Dt=%date%
set Tm=%time%
REM e.g.
REM Fri 12/19/2014
REM 8:20:04.13
for /f "tokens=2-4 delims=/ "  %%a in ("%date%") do (set MM=%%a& set DD=%%b& set YY=%%c)
for /f "tokens=1-4 delims=/:." %%a in ("%time%") do (set /a Hr=%%a& set Min=%%b& set Sec=%%c& set Mic=%%d)
REM If the hour is single digit, prefix it with a zero.
if %Hr% lss 10 set Hr=0%Hr%
set DateTimeNow=%YY%%MM%%DD%%Hr%%Min%%Sec%%Mic%
for %%a in (Dt Tm MM DD YY Hr Min Sec Mic)  do (set %%a=)

Open in new window


call DateTime-YYMMDDHHMMSSUU.bat
for %%a in ("\\dell-server\svrbackups\tramsDB\PERFECT_TRAVELDB.IB") do (echo ren %%a %%~na_%DateTimeNow%%%~xa)

Open in new window

Steve KnightIT ConsultancyCommented:
At the most basic level if you aren't too bothered about the date format you can add it using the output of %date%, one caveat being the format depends on the user running it, so it may be dd/mm/yyyy or mm/dd/yyyy or mm-dd-yyyy  ddd dd/mm/yyyy etc.

So the only thing to check specifically is change / to -, e.g.

RENAME "\\dell-server\svrbackups\tramsDB\PERFECT_TRAVELDB.IB" "PERFECT_TRAVELDB %date:/=-%.IB"

The %DATE:/=-% means take date output and change / into - character.

My article below shows some other methods of getting the date in the right format if you want something more specific:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html

Steve
doctorbillTechAuthor Commented:
Sorry but none of the above work
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

NVITEnd-user supportCommented:
> Sorry but none of the above work
Can you be more specific? i.e.
- What have you done to implement the above?
- Specific errors?
Bill PrewIT / Software Engineering ConsultantCommented:
NAMEDATE seems like it should work, what version are you using?

If you test it from the command prompt, with just the /X switch, what does it display?

What version of Windows are you running it on?

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doctorbillTechAuthor Commented:
latest version - 6.14
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, what does it report to the screen with just the /X option?

~bp
doctorbillTechAuthor Commented:
Problem appears to be sorted
If I run the batch file from task manager as a scheduled task it works fine
I assume the issue was a permissions problem
doctorbillTechAuthor Commented:
solved
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.