0

I have a batch script like below, it was working in our old server(2008), but when I moved it to new one it cannot update %d%:

rem @echo off 
@set path=c:\test;%path%

@set d=%date:~-4,4%%date:~4,2%%date:~-7,2% 
@set d=%d: =_% 
@set t=%time:~0,2%%time:~3,2%%time:~6,2% @set t=%t: =0%

Rem  Generate PGP encrypted file 
@echo Starting PGP... >> c:\apps\ftpLogs\test.log 
gpg2 --batch --yes -r testkey --output c:\test\foo\test_%d%.pgp --encrypt c:\test\foo\test_%d%.txt >> c:\apps\ftpLogs\test.log

When I am changing the %d% to today' date, the pgp and every thing works well , but in case of using %d% it's bypassing these lines. Any help will be much appreciated

user 12321
  • 2,846
  • 1
  • 24
  • 34
  • 2
    echo %date% on both machines and see if the format is the same. Date format varies by country. – RGuggisberg May 05 '15 at 20:10
  • that was the reason I said echo is not working as well, when I do echo %date% it will give me %date% as the answer. But the old server, is giving 05/05/2015 as the result of 'echo %date%' – user 12321 May 05 '15 at 20:15
  • check this - http://stackoverflow.com/questions/10945572/windows-batch-formatted-date-into-variable – npocmaka May 05 '15 at 20:33

2 Answers2

2

You have extensions disabled on the new server. Try

@echo off
    setlocal enableextensions
    echo %date%
MC ND
  • 69,615
  • 8
  • 84
  • 126
1

I'd start with an unambiguous date format as per Working with Dates and Times using WMI.

@echo off
for /F "tokens=2* delims==" %%G in (
    'wmic os get localdatetime/value'
) do @set "localdatetime=%%~G"
echo %localdatetime%

It should display something alike to 20150505222428.137000+120, which is the date displayed in the Universal Time Coordinate (UTC) format.

In the UTC format, dates are displayed as yyyymmddHHMMSS.xxxxxx±UUU, where:

yyyy   represents the year.
mm     represents the month.
dd     represents the day.
HH     represents the hour (in 24-hour format).
MM     represents the minutes.
SS     represents the seconds.
xxxxxx represents the milliseconds.
UUU    represents the difference, in minutes, between   
                      the local time zone and Greenwich Mean Time (GMT).

Example:

20150505222428.137000+120
yyyymmddHHMMSS.xxxxxx±UUU
JosefZ
  • 28,460
  • 5
  • 44
  • 83