0

is it possible to make a .bat file that would work like this :

  1. Get current date in dd.mm.yyyy format
  2. Change date to desired one
  3. Wait 60s
  4. Change date back to its original state
  5. exit

I know i can get current date by echo %date% and i get it in format dd.mm.yyyy but I have no idea how change it through one command, "set date" it's not working for me. I also know I could change date by simple command "date" then enter date but don't know how to automatize it. Can anyone write something like this?

epil0g
  • 19
  • 2
  • 1
    This site is not for people to write code for others. Show us *some* attempt to write the program and we will help you. – Idos Dec 02 '15 at 09:44
  • You can pipe the new date into the `date` command like `echo 31-12-15|date`, or redirect from a text file like `< "\path\to\file\with\date.txt" date`... – aschipfl Dec 02 '15 at 10:01

1 Answers1

1

To change the date you need admin permissions !

You can do it like echo 05.12.15|date

You can see how you can see how to get the date in a specific format and here you can see few tricks how to wait in batch .

Here's the script - (run it with admin privileges !):

@if (@X)==(@Y) @end /* jscript commend
@echo off

set "desired_date=03.12.15"

:: execute jscript part and get the date in a specific format
for /f "tokens=1-3 delims=- " %%A in ('cscript //E:JScript //nologo "%~f0"') do (
    set fdate=%%C.%%B.%%A
)

rem echo %fdate%

::change date
echo %desired_date%|date

::wait 60 seconds
typeperf "\IPv4\Datagrams Received/sec" -si 60 -sc 1 >nul 2>nul


::return date to its original state
echo %fdate%|date

exit /b 0
end of jscript commend*/

function GetCurrentDate() {
        // Today date time which will used to set as default date.
        var todayDate = new Date();
        todayDate = todayDate.getFullYear() + "-" +
                       ("0" + (todayDate.getMonth() + 1)).slice(-2) + "-" +
                       ("0" + todayDate.getDate()).slice(-2) + " " + ("0" + todayDate.getHours()).slice(-2) + ":" +
                       ("0" + todayDate.getMinutes()).slice(-2);

        return todayDate;
    }

WScript.Echo(GetCurrentDate());
Community
  • 1
  • 1
npocmaka
  • 51,748
  • 17
  • 123
  • 166