2

I'm using %date:~10%%date:~7,2%%date:~4,2%%time:~0,2%%time:~3,2% for date

The output should be like : 201706161102

but the output : 016.1102

whats wrong?

godilli
  • 33
  • 3
  • date format is dependent on the localization settings.To get the date independent from settings in the control panel check this - https://stackoverflow.com/a/19799236/388389 – npocmaka Jun 16 '17 at 08:11
  • Your server has a different date configuration to that which you expected. What is the value of `ECHO "%DATE%"` – Compo Jun 16 '17 at 08:11
  • @Compo 16.06.2017 – godilli Jun 16 '17 at 08:17
  • Based upon that output you could use `%DATE:~-4%%DATE:~-7,2%%DATE:~-10,2%%TIME:~0,2%%TIME:~3,2%` instead. – Compo Jun 16 '17 at 09:16

1 Answers1

1

I recommend you using the output of the WMIC command like that :

@echo off
Title Get Date and Time with WMIC
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
echo YYYYMMDDHHMinSec
Set "DateTimeVar=%YYYY%%MM%%DD%%HH%%Min%%Sec%"
echo %DateTimeVar%
pause
Hackoo
  • 15,943
  • 3
  • 28
  • 59