I am new to this forum and new to batch files on windows7.
I have a .csv file that contains thousands lines similar to those:
CLB,,,18l,,20150922,,2015-09-23 11:26:00 AM,,,2015-09-23 11:26:01 AM,,,,trad,,1344,,cam549,,,PUR,,,X001,,,PCL
CPC,,,3rs,,20150922,,2015-09-23 11:26:01 AM,,,2015-09-23 11:26:05 AM,,,,trad,,44,,cam388,,,CPC,,,X001,,,CPC
CPC,,,3rs,,20150922,,2015-09-24 11:29:00 PM,,,2015-09-24 11:29:12 PM,,,,ola,,43,,cam389,,,BPK,,,X002,,,D42
I am trying to convert AM/PM field4 (20150922,,2015-09-23 11:26:00 AM) and field5 (2015-09-23 11:26:01 AM) to 24hrs entries. For some reason !HOURS2! is always empty. I believe the problem is somewhere in the IF statement...Any idea why? and how I could make it work? Thanks!
This is the code I am using in a .bat file:
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "eol=; tokens=1,2,3,4,5,6,7,8,9,10,11 delims=," %%a in ('type C:\testing5.csv') do (
set CTS=%%d & set CTE=%%e
@echo CTS=!CTS! ---- CTE=!CTE!
for /f "tokens=1,2,3 delims= " %%o in ('echo !CTS!') do set CTIME1=%%p & set AMPM1=%%q
for /f "tokens=1,2,3 delims=:" %%r in ('echo !CTIME1!') do set HOURS1=%%r & set MINS1=%%s & set SECS1=%%t
set DSTAMPO=!HOURS1!!MINS1!!SECS1!
echo !DSTAMPO! AMPM=!AMPM1!
if !AMPM1!==PM (if !HOURS1! EQU 01 (set HOURS2=13)
if !HOURS1! EQU 02 (set HOURS2=14)
if !HOURS1! EQU 03 (set HOURS2=15)
if !HOURS1! EQU 04 (set HOURS2=16)
if !HOURS1! EQU 05 (set HOURS2=17)
if !HOURS1! EQU 06 (set HOURS2=18)
if !HOURS1! EQU 07 (set HOURS2=19)
if !HOURS1! EQU 08 (set HOURS2=20)
if !HOURS1! EQU 09 (set HOURS2=21)
if !HOURS1! EQU 10 (set HOURS2=22)
if !HOURS1! EQU 11 (set HOURS2=23)) ELSE (if !HOURS1! EQU 12 (set HOURS2=00))
echo hrs1!HOURS1!---hrs2!HOURS2!---
set DSTAMP=!HOURS1!!MINS1!!SECS1!
echo !DSTAMP!
set DSTAMP2=!HOURS2!!MINS1!!SECS1!
echo !DSTAMP2!
@echo -------------------------------------------------)
ENDLOCAL
Thanks much for your help!!!