Changing date format of text file column

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
camdenl
Posts: 1
Joined: 04 Jun 2013 14:18

Changing date format of text file column

#1 Post by camdenl » 04 Jun 2013 14:24

I have date and time in the first column of a comma delimited text file in this format:

MM/DD/YYYY H:M:S

and am trying to change it to:

YYYY/MM/DD H:M:S

I have been attempting to write a batch file for this, and have come up with this:

for /f "tokens=1-4 delims=/ " %%a in C:\Users\cs\Documents\headcur.csv do (
set "month=%%a"
set "day=%%b"
set "year=%%c"
set "mytime=%%d"
)
set "newtime=%year%/%month%/%day% %mytime%"
echo %newtime%

But nothing happens...

Could anyone point me in the right direction?

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Changing date format of text file column

#2 Post by Aacini » 04 Jun 2013 15:24

Don't you liked Endoro's answer at this site?

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Changing date format of text file column

#3 Post by Ocalabob » 04 Jun 2013 18:49

@Aacini
Aacini wrote:Don't you liked Endoro's answer at: <snip>

Good catch Aacini. Looks to me like Endoro is hard at work compiling a solution for the OP on that forum. It would be a shame for someone in this forum to spend a lot of time and effort to duplicate Endoro's work. Endoro is quite capable of problem solving. [/irritated

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Changing date format of text file column

#4 Post by foxidrive » 04 Jun 2013 22:51

Endoro's code skipped the data - but the OP didn't add the pertinent information for a while.

Even the code I added will modify the top header line too.

Post Reply