Date manipulation in batch files it nearly impossible to get right in a sensible way. The only thing you can do is support your culture and ignore the rest.
However, if you have the name of the file in a parameter to the batch (or a subroutine), you can use %~t1
. Otherwise the following:
for %%x in (%file%) do set datetime=%%~tx
On my machine this comes out as "2009-08-28 16:13" which can then be parsed into its individual parts:
:dissect_date_time
for /f "tokens=1-5 delims=-: " %%a in (%1) do set year=%%a&set month=%%b&set day=%%c&set hour=%%d&set minute=%%e
goto :eof
this is a subroutine you can call with
call :dissect_date_time %datetime%
and then you have the individual parts in their respective environment variables. Adapt accordingly to suit your date/time format. This one makes heavy use of for
as a tokenizer.
Once you have the individual parts you can try figuring out how old the file is by simply doing the same process with the current date/time and subtracting. Won't be much fun, but works.