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
Transform date time
Moderator: DosItHelp
Re: Transform date time
Use a FOR loop
Regards
aGerman
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
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
Regards
Dario
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
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Transform date time
Append leading characters:
08:23
11:23
or, should be faster:
08:23
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
Yeah. To make it in the same for loop you could use
Regards
aGerman
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