Search code examples
batch-filelogfile

How to write date and time to a log file on the same line using batch


I'm currently making a to write the date and time to a , but I can't find out how to keep the info on the same line of the .log.

REM Clear the screen
REM ------------------------------------------------------
cls


date /T >> C:\\myTemp\devTracker.log 
time /T >> C:\\myTemp\devTracker.log 


ECHO Starting Microsoft Visual Studio...

Solution

  • You can access the current date and time from a batch file using the predefined %date% and %time% variables without calling date.exe or time.exe. Just write them directly to the logfile using echo.

    echo %date% %time% >> C:\mytemp\devtracker.log