0

trying to setup a task in task scheduler to run every hour, I'm having trouble finding a way to add the date and time to the filename, looking for something concise like a one liner, or if needed, just something that works that i can put in a batch file, so far the idea is something like this:
netstat /anob >%USERPROFILE%\OneDrive\scripts\netstat\netstatlog_("%H%M%S").txt

this of course doesnt work as intended, but you see what i'm basically trying to do i hope

1

2 Answers 2

1

You can use %time% and extract individual parts from it.

For example, if echo %time% displays 21:41:30.85.

  • Hour = %time:~0,2%
  • Minute = %time:~3,2%
  • Second = %time:~6,2%

Then, echo %time:~0,2%%time:~3,2%%time:~6,2% will output 214130.

In you case, a one liner will look like so:

ping 8.8.8.8 > %USERPROFILE%\ping_%time:~0,2%%time:~3,2%%time:~6,2%.log

Similar operation can be applied to %date% to extract individual parts from current date.

0

You'll need to have the script create a new temporary variable(s) and then set the time/date into it after it's been properly formatted. Then have set your script to use the temporary variable. For a detailed explanation, follow the instructions in this link.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .