Robocopy creating a folder with the date in YYYYMMDD

Michael Smith 1 Reputation point
2022-12-16T04:02:42+00:00

Hi,
I am writing a bat file to create a folder on the desktop in the format MYOB_YYYYMMDD.
When I run the file all I get is a folder on the desktop with the name MYOB_022, I am not getting the full date.
Any help is greatly appreciated

@echo off  
  
:: Setting YYYYMMDD  
for /f "skip=1 tokens = 2-4 delims = (-)" %%a in ('echo/^|date') do (for /f "tokens = %t%-4 delims=.-/ " %%d in ('date/t') do (set %%a=%%d&set %%b=%%e&set %%c=%%f))  
  
:: Create folder with date on Desktop  
mkdir "C:\Users\michael.smith\Desktop\MYOB_%date:~10,4%%date:~7,2%%date:~4,2%"  
  
  
:: move from docs to desktop  
robocopy C:\Users\Public\Documents\MYOB "C:\Users\michael.smith\Desktop\MYOB_%date:~10,4%%date:~7,2%%date:~4,2%" /SEC /Z /E /log:C:\Users\michael.smith\Desktop\create_folder_copy_YYYYMMDD.txt /tee  
Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. WhTurner 1,611 Reputation points
    2022-12-16T10:51:14.347+00:00

    The tag "small-basic" is for Technical questions about Microsoft Small Basic, the only text-based programming language and IDE built for students to learn to code

    Please look for a more fitting tag as your question in not about Small Basic
    e.g. "c++" or "dotnet-csharp" or even "not-supported""

    0 comments No comments