3

I have the following script, but how can i make the %mytimestamp% as 20160929_132659 yyyymmdd_hhmmss format?

where i am getting invalid orientation and with comma:

di29092016_132659,71

set mydate=%date:/=%
set mytime=%time::=%
set mytimestamp=%mydate: =%_%mytime:.=_%

if exist "C:\scan\scan.zip" (
  if exist "\\be\c$\doc\scan.zip" (
    copy C:\scan\scan.zip "\\be\c$\doc\%mytimestamp%scan.zip"
  ) else (
    copy C:\scan\scan.zip "\\be\c$\doc"
  )

)
weston
  • 54,145
  • 21
  • 145
  • 203
  • 1
    What are the outputs of `echo %date%` and `echo %time%`? – SomethingDark Sep 29 '16 at 11:31
  • 1
    Possible duplicate of [How to get current datetime on Windows command line, in a suitable format for using in a filename?](http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us) – aschipfl Sep 29 '16 at 12:41
  • 1
    `for /F "tokens=2-7 delims=/:., " %%a in ("%date% %time%") do set mytimestamp=%%c%%b%%a_%%d%%e%%f` If this is not correct, blame my crystal ball that gave me wrong info! – Aacini Sep 29 '16 at 15:14

1 Answers1

0

Try this inside your batch file:

for /f "usebackq tokens=1,2,3,4,5,6,7 delims=/:. " %%a in (`echo %DATE% %TIME%`) do set NOW=%%d%%b%%c_%%e%%f%%g
@echo now: %NOW%
jftuga
  • 1,913
  • 5
  • 26
  • 49