Computing Staff
  • 2

Problem Converting 12-Hr To 24-Hr

  • 2

I’m trying to determine if files written to a buffer directory are less than 5KB. My problem lies in that FORFILES outputs time in 12-hr format while echo’ing %time% outputs in 24-hr.

This snippet is where I think I’m running into an issue. (I’m getting the Missing Operand error, and I can’t see where I’m going wrong… maybe I just need another set of eyes.)
[code]if NOT %%a==12 (
if %%d==PM (set /a hh=%%a+12) else (set /a hh=%%a)
) else (set /a hh=%%a)[/code]

This is the entire script.
[code]
REM Calls directory = %1
REM File size (bytes) = %2
REM Time check window (min) = %3

forfiles /p %1 /m *.wav /s /d -0 /c “cmd /c echo @fsize @ftime @fname” >> FSizes

echo ; > Problems

REM FORFILES adds an empty line at beginning of file. Remove it.
more +1 FSizes > FSizes2

for /f “tokens=1,2,3,4” %%i in (FSizes2) do (
REM Testing %%l

echo %%j:%%k> FileTimeRaw
for /f “tokens=1,2,3,4 delims=:” %%a in (FileTimeRaw) do (
if NOT %%a==12 (
if %%d==PM (set /a hh=%%a+12) else (set /a hh=%%a)
) else (set /a hh=%%a)
)
set /a mm=%%b
set filetime=%hh%%mm%
)

set /a timediff=%time:~0,2%%time:~3,2%-%filetime%

REM File is too old
if NOT %timediff% GTR %3 (

REM File is too big
if NOT %%i GTR %2 (

REM File is from yesterday
if NOT %timediff% LSS 0 (

echo SMALLFILE >> Problems
)
)
)
)

set x=0

for /f “eol=;” %%i in (Problems) do set /a x=%x%+1

echo %x%

:end
[/code]

Share

1 Answer

  1. Best Answer

    if NOT %%a==12 (
    if %%d==PM (set /a hh=%%a+12) else (set hh=%%a)
    ) else (set hh=%%a)

    Another point to ponder… if FileTimeRaw contains hours %%a as a two digit number which is 08 or 09 then Set /a will fail because Set /a considers any number beginning with 0 (zero) to be Octal (base 8) therefore 08 and 09 are invalid. This rule holds true whenever Set /a is used.

    Also set /a timediff=%time:~0,2%%time:~3,2%-%filetime%

    If %time…% returns 0605 and %filetime% contains 0555 the actual time difference is 10 mins because mins must be calculated in base 60 but because Set /a does the calculation in decimal timediff will be set to 50. The hours (hh) should be calculated in base 24. Unless, of course, if you can accept the decimal result.

    Good luck.

    Please come back & tell us if your problem is resolved.

    • 0