Hi, the text file contain below details

October 16, 2020 at 04:56:22
Specs: Windows 10
A|2020/06/06 06:15:00|
T|334

Need to use the above date in batch file.
Can you please help
How do get date part alone in the text and store the date in a variable
Will use that variable in batch file if conditions

message edited by Sundaram


See More: Hi, the text file contain below details


#1
October 16, 2020 at 05:50:22
::====== script starts here ===============
::
:: datevar.bat 2020-10-16 19:44:59.55
@echo off & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=2 delims=| " %%a in (IN.TXT) do (
set datevar=%%a
goto :done
)
:done
echo datevar=!datevar!
goto :eof

=====================

M2


Reply ↓  Report •

#2
October 16, 2020 at 07:36:37
@echo off
for /f "tokens=2 delims=| " %%a in (in.txt) do (
set datevar=%%a
goto :done
)
:done
for /f "tokens=2 delims=| " %%a in (out.txt) do (
set datevar1=%%a
goto :done
)
:done
echo %datevar%
echo %datevar1%
IF %datevar% == %datevar1%
(
echo "same"
)
else
(
echo "not smae"
)
getting syntax error in if condition
can you please help this

Reply ↓  Report •

#3
October 16, 2020 at 08:15:53
A classic case of parenthesis interruptus

==================
@echo off
for /f "tokens=2 delims=| " %%a in (in.txt) do (
set datevar=%%a
goto :done
)
:done
for /f "tokens=2 delims=| " %%a in (out.txt) do (
set datevar1=%%a
goto :done
)
:done
echo %datevar%
echo %datevar1%
IF %datevar% == %datevar1% (
echo "same"
) else (
echo "not smae"
)

=====================

M2


Reply ↓  Report •

Related Solutions

#4
October 17, 2020 at 04:38:50
Did you mean date without Time or Both Date and Time ?

Reply ↓  Report •

#5
October 17, 2020 at 04:45:10
Need both date and time.

Reply ↓  Report •

#6
October 17, 2020 at 05:41:38
@Sundaram in this case you can use regex with powershell easily like that :

cls
$Data = "A|2020/06/06 06:15:00| T|334"
$pattern = "(19|20)[\d]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][\d]|3[01]) (\d\d:\d\d:\d\d)"
$result=[regex]::Match($Data,$pattern).Value
$result


Reply ↓  Report •

#7
October 17, 2020 at 06:57:39
more simply:

@echo off
for /f "tokens=2 delims=| " %%a in (in.txt) do (
set datevar=%%a
goto :done
)
:done
for /f "tokens=2 delims=| " %%a in (out.txt) do (
set datevar1=%%a
goto :done
)
:done
echo %datevar%
echo %datevar1%
IF %datevar% == %datevar1% (
echo "same"
) else (
echo "not smae"
)

=====================

M2


Reply ↓  Report •

#8
October 17, 2020 at 11:31:08
I know it doesn't matter here, but the fact that you keep not
catching and not fixing the mis-spelling of the word "same"
is really bugging me, even if it isn't bugging the program.

-- Jeff, in Minneapolis


Reply ↓  Report •

#9
October 18, 2020 at 23:07:24
One more change
A|2020/06/06 06:15:00|
T|334
Need to use the above date in batch file.
Can you please help
How do get date part alone in the text and store the date in a variable as "variable1" and

Need to get the file last modified date that Will store another variable as"variable 2"

Now just compare the two date

If ( variable1 > variable2)
(
)
Else if ( variable1 < variable2)
()
Else
()


Reply ↓  Report •

Ask Question