This is very easy to achieve:
@echo off
for /F "delims=" %%I in ('dir * /A-D /B /O-D 2^>nul') do set "NewestFileTime=%%~tI" & goto NewestFileTime
echo There is no file in current directory.
exit /B
:NewestFileTime
echo Last modification time of newest file is: %NewestFileTime%
Please note that the format of the date and time string assigned to the environment variable NewestFileTime
depends on Windows Region and Language settings set for the current user account respectively the account used on running this batch file.
There is also the possibility to get the last modification time of the newest file in a region-independent format, see answer on Find out if file is older than 4 hours in batch file for details.
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
dir /?
echo /?
exit /?
for /?
goto /?
set /?
See also single line with multiple commands using Windows batch file for an explanation of the unconditional AND operator &
used in this batch code.