For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)
Here mydate is 20180416. How to get the date in yymmdd format here?
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)
Here mydate is 20180416. How to get the date in yymmdd format here?
 
    
    For your specific locale dependent method, you just need to add an additional line removing the first two characters:
@Echo Off
For /F "Tokens=2-4 Delims=/ " %%A In ('Date /T') Do Set "mydate=%%C%%A%%B"
Set "mydate=%mydate:~2%"
Echo [%mydate%]
Timeout -1
Although for that format you could probably do it even simpler:
@Echo Off
Set mydate="%DATE:~-2%%DATE:~-10,2%%DATE:~-7,2%"
Echo [%mydate%]
Timeout -1
Alternatively for a locale independent method…
You could use RoboCopy:
@Echo Off
For /F "Tokens=1-3 Delims=/ " %%A In ('RoboCopy/NJH /L "\|" Null'
) Do Set "mydate=%%A%%B%%C" & GoTo :Break
:Break
Set "mydate=%mydate:~2%"
Echo [%mydate%]
Timeout -1
WMIC:
@Echo Off
For /F "EOL=L" %%A In ('WMIC OS Get LocalDateTime'
) Do Set "mydate=%%~nA" & GoTo :Break
:Break
Set "mydate=%mydate:~2,6%"
Echo [%mydate%]
Timeout -1
MakeCab:
@Echo Off
Set "df=%TEMP%\~foo.ddf"&Set "tf=%TEMP%\~%RANDOM%"
Set /A "Jan=1,Feb=2,Mar=3,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9,Oct=10,Nov=11,Dec=12"
(   Echo .Set InfHeader=""&Echo .Set InfSectionOrder=""&Echo .Set InfFooter="%%2"
    For /L %%A In (1 1 4) Do Echo .Set InfFooter%%A=""
    Echo .Set Cabinet="OFF"&Echo .Set Compress="OFF"&Echo .Set DoNotCopyFiles="ON"
    Echo .Set RptFileName="NUL")>"%df%"
MakeCab /D InfFileName="%tf%" /F "%df%">Nul
For /F "UseBackQ Tokens=2-3,5" %%A In ("%tf%") Do Set /A "mm=%%A,dd=10%%B,yyyy=%%C"
Del "%tf%" "%df%">Nul 2>&1&Set "mm=10%mm%"
Set "mydate=%yyyy:~-2%%mm:~-2%%dd:~2%"
Echo [%mydate%]
Timeout -1
Or even utilise PowerShell:
@Echo Off
For /F %%A In ('PowerShell "(Get-Date).ToString('yyMMdd')"') Do Set "mydate=%%A"
Echo [%mydate%]
Timeout -1
