Report

Batch script help please [Solved]

Ask a question BrianGreen 883Posts Saturday January 17, 2015Registration date ModeratorStatus December 8, 2016 Last seen - Last answered on Mar 10, 2016 09:30AM
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.
See more 
Helpful
+0
moins plus
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!

Add comment

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!