Help with command

S-Soft 666 Reputation points
2022-12-03T03:49:47.833+00:00

Hello,
Writing a simple batch file and don't know how to store the current date and revert back to it later?
Something like:

Set DateString=%Date%
...
Date DateString

The system cannot accept the date entered.

sorry but didn't find a tag for command prompt/ batch scripting, but am sure it's so simple :)
Please advise :)

Windows for business Windows Client for IT Pros User experience Other
{count} votes

2 answers

Sort by: Most helpful
  1. Cristian SPIRIDON 4,486 Reputation points Volunteer Moderator
    2022-12-03T07:09:49.603+00:00

    Hi,

    It maybe case sensitive (is shouldn't, but just an idea) and you can try to simplify the bat and see where it breaks.

    Here is an example that should work:

    https://stackoverflow.com/questions/3672079/can-a-batch-file-change-the-system-date-save-file-with-attributes-change-date

    And you need to be admin.

    Hope this helps!


  2. MotoX80 36,291 Reputation points
    2022-12-05T13:35:38.913+00:00

    set DateString=%date:~4%
    echo %DateString%

    I use this when I want to create a log file name with date and time.

    echo "myapp.%date:~10,4%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%%time:~6,2%.log"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.