>for %a in (a.txt) do set FileDate=%~ta ----gives date and time
>set FileDate=08/21/2012 02:36 PM
which is modified date and time
>for %a in (a.txt) do set FileDate=%FileDate:~0,10%-- gives date only
>set FileDate=08/21/2012
but i need only time
how to get it?
Please help
how to get modified time of the file in batch file DOS
Moderator: DosItHelp
Re: how to get modified time of the file in batch file DOS
Try this:
for %a in (a.txt) do set filedate=%~ta
echo %FileDate:~-8%
for %a in (a.txt) do set filedate=%~ta
echo %FileDate:~-8%
Re: how to get modified time of the file in batch file DOS
I got with
ECHO %FileDate:~11%
any ways
Thanks a lot
ECHO %FileDate:~11%
any ways
Thanks a lot
Re: how to get modified time of the file in batch file DOS
sonalir wrote:I got with
ECHO %FileDate:~11%
any ways
Thanks a lot
Either way will work.
Re: how to get modified time of the file in batch file DOS
If you want to go the Math route you can break up your file date into variables.
Remember that you will need to remove the leading zero from hours 1 through 9.
Code: Select all
@echo off
for %%a in (myfile.txt) do (
for /f "tokens=1-4 delims=: " %%G in ('echo %%~ta') do (
set date=%%G
set hour=%%H
set min=%%I
set ampm=%%J
)
)
set date
set hour
set min
set ampm
pause
Remember that you will need to remove the leading zero from hours 1 through 9.