T
T
Timofey Shestakov2020-07-22 15:47:47
cmd/bat
Timofey Shestakov, 2020-07-22 15:47:47

How to fix a condition on the command line?

@echo off
set VDATE=%date:~-10%
set VTIME=%time:~0,-3%
cd C:\Users\Asus\Desktop
@echo %VDATE% %VTIME%>tida.txt
if %VTIME:~0,2% geq 12 copy tida.txt tida.bak || @echo %VDATE% %VTIME%>tida.txt else @echo %VDATE%
@pause

When VTIME is less than 12, you need to display VDATE, but it does not display it, it shows the executed commands, and it also writes the new time and date replacing the old ones, and not in the next line.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-07-22
@ioshiku

@echo off
set VDATE=%date:~-10%
set VTIME=%time:~0,-3%
echo %VDATE% %VTIME% >> test.txt
if %VTIME:~0,2% geq 12 (copy test.txt test.bak || echo %VDATE% %VTIME% >> test.txt) else echo %VDATE%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question