INFORMATICS

The Best

Przełącznik języka

Zaproś mnie na KAWE

Jeżeli podoba Ci się strona i chcesz wspomóc projekt!

Postaw mi kawę na buycoffee.to

This Site

Płatnik

CMS

Hardware

Uncategorised

Emulators

Powershell

Storage Array

DNS

Antivirus program

Licznik

2.png8.png9.png1.png5.png3.png2.png
Today553
Yesterday728
This week3626
This month11657
Total2891532

Visitor Info

  • IP: 3.144.244.44
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

4
Online

czwartek, 18 kwiecień 2024 17:18

Add date fo file name

Gwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywna
 
 

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