0

I have a batch script that backs up a folder to another folder etc and names the backed up folder to %date% %time% etc(only shows date currently) and I want it to show only hours and minutes. if I use %time::=.% i get 21.46.56.26 etc but I want only the 21.46 and nothing else.

Script:

title Backing up the universe..
echo Backing up the universe..

set savedate=%date:/=.%
set savetime=%time::=.%
echo Set Variable 'savedate' to %savedate%
echo Set Variable 'savetime' to %savetime%

pause

md Universe-Backup\"%savedate%"
echo Created backup folder.
pause
echo %savedate%

robocopy %CD%\Universe\ %CD%\Universe-Backup\\"%savedate%" /e

title The universe has been backedup!
echo The universe has been backedup!
title Starting server..
echo Starting server..
START %CD%\Server.exe
aschipfl
  • 28,946
  • 10
  • 45
  • 77
  • 2
    You could use `set savetime=%time:~,5%` to just get the first 5 characters. However, are you aware that `%date%` and `%time%` variables return date and time in a locale-dependent manner? Perhaps you should take a look at this: [How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?](https://stackoverflow.com/q/203090)… – aschipfl Nov 26 '20 at 19:52
  • i dont get anything you sent me sorry. can you summarize the thing real quick? – Soviet peanut Nov 26 '20 at 20:01
  • 1
    Well, seems you have got it, your answer exactly reflects my suggestion… – aschipfl Nov 26 '20 at 20:17

2 Answers2

0

I fixed it by doing this thing:

@echo off
title Backing up the universe..
echo Backing up the universe..

set savedate=%date:/=.%
set savetime=%time:~,5%
set backuptime=%savetime::=.%
echo Set Variable 'savedate' to %savedate%
echo Set Variable 'savetime' to %backuptime%

pause

md Universe-Backup\"%savedate%"
echo Created backup folder.
pause
echo %savedate%

robocopy %CD%\Universe\ %CD%\Universe-Backup\\"%savedate%" /e

title The universe has been backedup!
echo The universe has been backedup!
title Starting server..
echo Starting server..
START %CD%\Server.exe

basically I just took the first few things and replaced all the : with dots!

0

As you're already using Robocopy.exe, I'd suggest you use this non local dependent method of getting your date and time information.

@Echo Off
SetLocal EnableExtensions
Set "d=" & Set "t="
For /F "Tokens=1-5 Delims=/: " %%G In (
    '""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""'
) Do Set "d=%%G.%%H.%%I" & Set "t=%%J.%%K"
Echo=%d% %t% & "%__AppDir__%timeout.exe" /T 5 1> NUL

The last line is included just to show you the variable values, you'd obviously adjust that for your specific commands. I've used %%G.%%H.%%I for yyyy.MM.dd, you can adjust their positions if you've decided not to order them in a sortable order.

Compo
  • 30,301
  • 4
  • 20
  • 32