1

Does anyone know how to set YYMMDD (not 4xYYYY) as a date format in batch? All i found was yyyymmdd, but I just need the two last numbers in the year. So instead of 2015, I need 15 as the output.

I've got this so far;

set mydate=%date:~6,4%%date:~3,2%%date:~0,2%
echo %mydate%

This gives me todays date in this format; 20151214, which isn't what I need.

MadsTheMan
  • 705
  • 1
  • 10
  • 32

2 Answers2

4

%date:~6,4% means "from the DATE variable take a substring starting with the 7th char (it starts with ZERO for the first char, so 6 means the seventh char) with length=4. Once you understand that, it's easy: %date:~8,2%

NOTE: this method depends on individual computersettings and therefore doesn't work correct on every Computer. I suggest reading this. To extract 'YYMMDD' only, Change the last line there to: set mydate=%datetime:~2,6%

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • That worked like a charm, thanks! And thank you for the explanation as well. Did not know that was the way it worked. – MadsTheMan Dec 14 '15 at 07:45
  • 1
    It's described in detail when you do a `set /?` on the command prompt (a lot to read, but worth the time) – Stephan Dec 14 '15 at 08:06
2
set mydate=%date:~8,2%%date:~3,2%%date:~0,2%
echo %mydate%
Magoo
  • 77,302
  • 8
  • 62
  • 84