Changing date from MM/DD/YY to MM/DD/YYYY format
Posted: 05 Nov 2015 07:12
Hi Team,
I have a requirement where I need to change the date format of the columns. Here I have provided my script, input file, output file and the desired output file. Please suggest the changes required in my script to get the desired output. Currently I am getting the output in the MM/DD/YY format but my system only supports the MM/DD/YYYY format. So please help me in achieving the required result. Thanks...!!
Code:
Input File:
Output File:
Desired Output File:
Thanks for your help and time..!!
Regards,
Shaswat
I have a requirement where I need to change the date format of the columns. Here I have provided my script, input file, output file and the desired output file. Please suggest the changes required in my script to get the desired output. Currently I am getting the output in the MM/DD/YY format but my system only supports the MM/DD/YYYY format. So please help me in achieving the required result. Thanks...!!
Code:
Code: Select all
@echo off
setlocal enableDelayedExpansion
set m=100
for %%M in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /a m+=1
set "%%M=!m:~1!"
)
:: 1 2 3 4 5 6
set "find1=(^|,)(\d)?(\d)-([a-z]{3})-(\d\d)(?=,|$)"
set "repl1=env($5)?($2+env($5)+'/'+($3?$3:'0')+$4+'/'+$6):$0"
:: 7 8 9 10 11 12
set "find2=(^|,)(\d)?(\d/)(\d)?(\d/\d\d)(?=,|$)"
set "repl2=$8+($9?$9:'0')+$10+($11?$11:'0')+$12"
call jrepl "%find1%@%find2%" "%repl1%@%repl2%" /i /j /t @ /f "input.csv" /o "dateformat.csv"
for /f "tokens=1-8 delims=|" %%a in ('parseCSV.bat "/o:|" ^<dateformat.csv') do (
echo "%%~a","%%~b","%%~c","%%~d","%%~e","%%~f","%%~g","%%~h">>output.csv
echo "Wait......Processing Files...!!!"
)
Input File:
Code: Select all
17-Aug-15,516121,PSAM,14-Aug-15,O,Option,42655,8/21/15
21-Jan-11,516121,PSAM,17-Aug-15,CU,Currency,42642,3/15/14
15-Dec-13,516121,PSAM,19-Aug-15,CU,Currency,42643,6/28/15
Output File:
Code: Select all
08/17/15,516121,PSAM,08/14/15,O,Option,42655,08/21/15
01/21/11,516121,PSAM,08/17/15,CU,Currency,42642,03/15/14
12/15/13,516121,PSAM,08/19/15,CU,Currency,42643,06/28/15
Desired Output File:
Code: Select all
08/17/2015,516121,PSAM,08/14/2015,O,Option,42655,08/21/2015
01/21/2011,516121,PSAM,08/17/2015,CU,Currency,42642,03/15/2014
12/15/2013,516121,PSAM,08/19/2015,CU,Currency,42643,06/28/2015
Thanks for your help and time..!!
Regards,
Shaswat