Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the current time in a Batch-File?

I need to print time in a batch file but command prompt tells me that the syntax is incorrect. Here is the code i have so far:

@echo %time% ping -n 1 -w 1 127.0.0.1 1>nul @echo %time% pause cls 

I don't know why it isn't working, Please help Me.

like image 275
user2975367 Avatar asked Nov 11 '13 05:11

user2975367


People also ask

How do I timestamp in CMD?

You can use $T for time and $D for date, as well as several other expansions. See also: https://ss64.com/nt/prompt.html. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/prompt.

How do I get current date time on the Windows command line?

cmd - Script to get current time. GMT. cmd - Current time in GMT (World Time). Equivalent PowerShell: Get-Date - Get current date and time.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


1 Answers

This works with Windows 10, 8.x, 7, and possibly further back:

@echo Started: %date% %time% . . . @echo Completed: %date% %time% 
like image 73
Erik Anderson Avatar answered Oct 06 '22 14:10

Erik Anderson