INFORMATICS

The Best

Add date fo file name

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 
 

I usually do it this way whenever I need a date/time string:

SHOW actual settings
echo %DATE%
23.11.2022
echo %time%
13:21:03,46

SET backup_file_name=%COMPUTERNAME%.%date:~6,4%-%date:~3,2%-%date:~0,2%_h_%time:~0,2%-%time:~3,2%.PGDMP

set dt=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%__%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2% set dt=%dt: =0%

The resulting string has the format: - SrvPoint.SrvPOINT.1-23-2--20_h_11-16.PGDMP


Short explanation of how substrings work:

%VARIABLE:~num_chars_to_skip,num_chars_to_keep%

So to get just the year from a date like "23.11.2022" use:

%DATE:~6,4%
       ^-----skip 6 characters
         ^---keep 4 characters 

 

Search