'how to set date to current date using dos batch file command

how to set date to current date using dos batch file command.



Solution 1:[1]

The date command is what you are looking for. This works on my Windows XP box:

date 15-02-2010

Notice the formatting dd-MM-yyyy, which seems to be required here, probably because of my regional settings being set to Denmark. The documentation states that the format is MM-dd-yy, but on my computer, the day and month fields gets flipped if the date is written in that format.

Solution 2:[2]

When you type "date" on the dos command it will show you the date specified in your bios, and ask you to set the current date (you can set this if the date in your bios is not the current). The system has no ability to know if it's date is correct.

If you have a server with correct date, you can use "net time" so the the client can synchronize with the server.

NET TIME <SERVERNAME> /SET

or

NET TIME \\SERVERNAME /SET /YES

Solution 3:[3]

This should work if you have the "Set time automatically" option on:

net stop w32time    
net start w32time
w32tm /resync /nowait

Or you can save the current date to a text file and then pass the current date to the date command:

date /t>current_date.txt

OR

echo %date%>current_date.txt

Then pass the current date to the date command:

date<current_date.txt

Solution 4:[4]

You must take in account that US date is a bit different from europe date. Giving Date displayes:

>date
The current date is: 2019-09-12
Enter the new date: (yy-mm-dd)
But US date will be something like: mm-dd-yy

Better have a look at: https://www.robvanderwoude.com/batexamples.php

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jørn Schou-Rode
Solution 2 xploshioOn
Solution 3
Solution 4