0

I have a computer running Window Server 2008 R2 Standard. It runs several periodic tasks written by Windows cmd.

Recently these batch jobs work improperly and i realize that the logic of the script was broken. It is because is this server when you display %date% variable, what you receive in stdout is:

  1. Actual value - break the logic of the script:
C:>echo %date% 
01/09/2019
  1. The output of %date% variable should be as below (What i expect (also default format of %date% variable )
C:>echo %date%
Wed 01/09/2019

I have tried several tutorial to modify on registry but it was unsuccessful. Restarting server is restricted since other important applications are running .

Please suggest any resolution for this issue?

1 Answer 1

2

The %date% variable displays date in current short date format as defined in the Region control panel (see short date drop-down menu):

Region..Formats

The following script shows how the %date% appearance changes for MM/dd/yyyy and M/d/yyyy formats:

@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
echo(

set "regKey=HKCU\Control Panel\International"

rem retrieve current sShortDate format 
for /F "skip=2 tokens=1,2*" %%G in ('
  reg query "%regKey%" -v sShortDate
  ') do (
    set "sShortDateBkp=%%I"
    set "sShortDateTyp=%%H"  not used, always REG_SZ
)
echo current  sShortDate format=%sShortDateBkp%  %%date%%=%date%

rem change the sShortDate format to M/d/yyyy
set "sShortDateNew=M/d/yyyy"
>NUL REG ADD "%regKey%" /v sShortDate /t REG_SZ /d "%sShortDateNew%" /f
echo changed  sShortDate format=%sShortDateNew%    %%date%%=%date%

rem change the sShortDate format back to its original value 
>NUL REG ADD "%regKey%" /v sShortDate /t REG_SZ /d "%sShortDateBkp%" /f
echo original sShortDate format=%sShortDateBkp%  %%date%%=%date%

Output:

==> D:\bat\SF\948175.bat

current  sShortDate format=MM/dd/yyyy  %date%=02/07/2019
changed  sShortDate format=M/d/yyyy    %date%=Thu 02/07/2019
original sShortDate format=MM/dd/yyyy  %date%=02/07/2019

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .