This is to show you how to grep the date time as specified format. The purpose is for script to generate a file name with date time indicated, such as Backup_2024_04_14.bak. So that you can notified when the backup process to build this file.
To try this, you may run CMD in Windows environment to open a command prompt. After that, run below commands.
First command to grep the date time format YYYYMMDD_hhmmss. However, if the hh is less than 10am (such as 00 to 09), hh will being a empty space with a single digit, so the file name will become YYYYMMDD_ hmmss.bak. This is not friendly for script in some environment because script may not able to handle the file name with space. Therefore, the second command is to find any space in the dt variable and the replace it by 0. So the file name will become YYYYMMDD_0hmmss.bak.
set dt=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%__%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2%
set dt=%dt: =0%