It sounds like a bad idea to be parsing a date that could be in various formats which format you don't know. Better to get the date in a specific format, even if that means not pure batch but invoking powershell.
C:\Users\tod>for /f %a in ('C:\Windows\System32\WindowsPowershell\v1.0\powershell -Command "Get-Date -format yyyy_MM_dd__HH_mm_ss"') do set datetime=%a
C:\Users\tod>set datetime=2018_01_22__09_15_33
or without time.
C:\Users\tod>for /f %a in ('C:\Windows\System32\WindowsPowershell\v1.0\powershell -Command "Get-Date -format yyyy_MM_dd"') do set datetime=%a
C:\Users\tod>set datetime=2018_01_22
C:\Users\tod>
Once you have that you can do
C:\Users\tod>echo %datetime:~0,4%
2018
C:\Users\tod>
And so on.. So you can set whatever variable to equal the year, month, date in month.
Added
If you wanted to not use powershell and you don't mind that this will only work for US formatted dates.
C:\Users\tod>echo %date%
01/22/2018
C:\Users\tod>echo %date:~0,2%
01
C:\Users\tod>echo %date:~3,2%
22
C:\Users\tod>echo %date:~6,4%
2018
C:\Users\tod>
So you really should be able to see how to do it
set first=%date:~0,2%
set second=%date:~3,2%
set third=%date:~6,4%
C:\Users\tod>set first=%date:~0,2%
C:\Users\tod>set second=%date:~3,2%
C:\Users\tod>set third=%date:~6,4%
C:\Users\tod>echo %first%/%second%/%third%
01/22/2018
C:\Users\tod>echo %second%/%first%/%third%
22/01/2018
C:\Users\tod>
So you can say set ukdate=%second%/%first%/%third% and you can say echo %ukdate%
And that non-powershell method only works if you know the format of the date on the system, and know that it's US. I would generally recommend against batch, because for example what if a new revision of the OS comes along and the output of a command is a bit different and your code presumes a particular format in its parsing. And while in this case batch is in one sense, neat, sometimes it can be like banging sticks together. It's a good idea to know batch and to use it a bit but to install some other scripting language like Ruby or Python or Golang or NodeJS. But if you want to use solely batch for this, then there it is.
1
just a simple google gives tons of solutions right away https://stackoverflow.com/q/15378719/995714 https://serverfault.com/q/227345/343888
– phuclv – 2018-02-12T16:04:01.8771
Possible duplicate of How to get the Date in a batch file in a predictable format?
– phuclv – 2018-02-12T16:04:12.0801@LưuVĩnhPhúc, those links are all about extracting date components from the system date. This question is about converting part of a filename to a recognizable date. I'm not sure if the answers on those questions get someone usefully close to a solution to this problem. – fixer1234 – 2018-02-13T07:05:47.273