Bring some characrets from a .txt and "tidy" them

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
giulia.1996
Posts: 2
Joined: 19 Feb 2020 04:47

Bring some characrets from a .txt and "tidy" them

#1 Post by giulia.1996 » 20 Feb 2020 07:16

Hello,

I have a .txt file with this content (it's a date with a "space" character at the end of the string):

20/02/2020

I need to bring the characters for have a YYYYMMDD format, like this (without the slash):

20200220

How can I do it?

Thank you

penpen
Expert
Posts: 1786
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Bring some characrets from a .txt and "tidy" them

#2 Post by penpen » 20 Feb 2020 13:13

You might want to use a for/f-loop to split the parts of the date:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
set "input=20/02/2020 "
for /f "tokens=1-3 delims=/ " %%a in ("%input%") do set "timestamp=%%~c%%~b%%~a"
echo("%timestamp%"
goto :eof
Note that dates are localized strings and therefore highly system dependent.


penpen

Post Reply