Page 1 of 1
Transform date time
Posted: 21 Sep 2010 08:18
by darioit
Hello everybody,
how can I transform this "21/09/2010 16.04.32"
to this format "2010-09-21 16:04:32.00"
Regards
Dario
Re: Transform date time
Posted: 21 Sep 2010 08:28
by aGerman
Use a FOR loop
Code: Select all
@echo off &setlocal
set "oldDatetime=21/09/2010 16.04.32"
for /f "tokens=1-6 delims=/. " %%a in ("%oldDatetime%") do set "newDatetime=%%c-%%b-%%a %%d:%%e:%%f.00"
echo %newDatetime%
pause
Regards
aGerman
Re: Transform date time
Posted: 22 Sep 2010 02:13
by darioit
Thanks it works,
but if the hour is below 10 I loose 0 below
8:52:28.00 instead 08:52:28.00
the script to take date/time of file is this
Code: Select all
>"%temp%\tmp.vbs" ECHO WScript.Echo WScript.CreateObject("Scripting.FileSystemObject").GetFile(WScript.Arguments(0)).DateLastModified
FOR /f "delims=" %%a IN ('cscript //nologo "%temp%\tmp.vbs" "%2"') DO SET "DateTime=%%a"
Regards
Dario
Re: Transform date time
Posted: 22 Sep 2010 02:51
by orange_batch
Append leading characters:
Code: Select all
set hour=8
set hour=0%hour%
set hour=%hour:~-2%
set minutes=23
echo:%hour%:%minutes%
08:23
Code: Select all
set hour=11
set hour=0%hour%
set hour=%hour:~-2%
set minutes=23
echo:%hour%:%minutes%
11:23
or, should be faster:
Code: Select all
setlocal enabledelayedexpansion
set hour=8
if %hour% LSS 10 set hour=0%hour%&set hour=!hour:~-2!
set minutes=23
echo:%hour%:%minutes%
08:23
Re: Transform date time
Posted: 22 Sep 2010 16:13
by aGerman
Yeah. To make it in the same for loop you could use
Code: Select all
@echo off &setlocal
set "oldDatetime=21/09/2010 6.04.32"
for /f "tokens=1-6 delims=/. " %%a in ("%oldDatetime%") do (set "H=0%%d" &call set "newDatetime=%%c-%%b-%%a %%H:~-2%%:%%e:%%f.00")
echo %newDatetime%
pause
Regards
aGerman