Page 1 of 1

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

Posted: 20 Feb 2020 07:16
by giulia.1996
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

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

Posted: 20 Feb 2020 13:13
by penpen
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