Batch script help please

Solved/Closed
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Mar 10, 2016 at 09:17 AM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Mar 10, 2016 at 09:30 AM
Hi Guys,

Im here again with a "simple" problem ...

Im having problems trying to get a section of my .bat script to work so I added some echos to see whats going on and where. Can anyone tell me why this doesnt show the echo of the second %dd%? (These development echos are surrounded by REM +++++++ so they are easy to find and delete when it all works). The things I am talking about are inside of these "Development markers"

The code you see is from the start of my script. There are bits after, but not sure if you need these. Let me know if you do.
CLS
@Echo Off

REM ###############################################################
REM # This gets the date in the correct format for the filename #
REM ###############################################################

FOR /F "TOKENS=1 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dd=%%A
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2,3 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET yyyy=%%C

SET yy=%yyyy:~-2%

REM ###############################################################
REM ## Find what day/time it is so correct day/shift can be set ##
REM ###############################################################
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Day = %dd%
pause
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SET currentTime=%TIME%

rem Change currentTime into CentiSeconds
FOR /F "tokens=1-4 delims=:.," %%a in ("%currentTime%") do (
SET /A "csTimeA=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)

IF %csTimeA% GTR 8280000 set "template=EVE"
IF %csTimeA% LSS 2630000 (
set "template=EVE"
set /A dd=%dd%-1
)

IF %csTimeA% GTR 2520000 (
IF %csTimeA% LSS 5490000 set "template=NHT"
set /A dd=%dd%-1
)

IF %csTimeA% GTR 5400000 (
IF %csTimeA% LSS 8370000 set "template=DAY"
IF %dd% LSS 10 SET dd=%dd:~1%
)

rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Template = %template%
pause
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo %dd%
pause
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The odd thing is that the script does actually work when the template is set to NTS (ie if it is run after 07:00 and before 15:00), but not for when it is set to DAY (ie run after 15:00 and before 23:00). These variables which are not altered again are used later on in the script.

What am I doing wrong please?

Thanks all. As always theres a virtual beer in it for the solution finder.

I really appreciate thank you messages as a payment for solving issues   :o)

1 response

BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 149
Mar 10, 2016 at 09:30 AM
Oh POO!

I forgot a - sign right at the end. The last working line should have been

IF %dd% LSS 10 SET dd=%dd:~-1%

At least I get a nice beer!

I really appreciate thank you messages as a payment for solving issues   :o)
0