Trying to advance time two weeks at a time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rain
Posts: 2
Joined: 05 Apr 2017 15:13

Trying to advance time two weeks at a time

#1 Post by Rain » 05 Apr 2017 15:20

hello so i am new here and trying to create a batch that advancesa month every...20 seconds for example
i have this script which i was able to compile however to do what i want to do i have to keep changing the date manually on the script
set before=%date%
echo 04/06/2017 | date
ping localhost -n 15
echo %before% | date

so i am after a way to set it to repeat but change by a month at a time
as the way ive done it i have to change it myself instead of it doing this for example:

set before=%date%
echo 04/07/2017 | date
ping localhost -n 15
echo echo 04/08/2017 | date
ping localhost -n 15
echo echo 04/09/2017 | date

but i would be sitting here for some time writing out infinite dates
many thanks and any advice is welcome im new to scripting

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Trying to advance time two weeks at a time

#2 Post by penpen » 06 Apr 2017 05:01

You should avoid playing with date and time, because there may be unwanted side effects:
For example some virus scanners may notice the date modification of one month and handle it as "another month worked", so the (possibly paid) virus protection expires another month earlier (even if you restore the date).

Nevertheless, if you want to get the values (assuming your system is using the date format dd/mm/yy), then this might help you:

Code: Select all

:: get date format and values
for /f "tokens=1-3 delims=./-" %%a in ("%before%") do (
   set "day=%%~a"
   set "month=%%~b"
   set "year=%%~c"
)

:: remove trailing zeroes and inc month value
set "day=%day:*0=%"
set "month=%month:*0=%"
You then can change the values using "set /a" for example.


penpen

Rain
Posts: 2
Joined: 05 Apr 2017 15:13

Re: Trying to advance time two weeks at a time

#3 Post by Rain » 09 Apr 2017 09:21

penpen wrote:You should avoid playing with date and time, because there may be unwanted side effects:
For example some virus scanners may notice the date modification of one month and handle it as "another month worked", so the (possibly paid) virus protection expires another month earlier (even if you restore the date).

Nevertheless, if you want to get the values (assuming your system is using the date format dd/mm/yy), then this might help you:

Code: Select all

:: get date format and values
for /f "tokens=1-3 delims=./-" %%a in ("%before%") do (
   set "day=%%~a"
   set "month=%%~b"
   set "year=%%~c"
)

:: remove trailing zeroes and inc month value
set "day=%day:*0=%"
set "month=%month:*0=%"
You then can change the values using "set /a" for example.


penpen


many thanks and this will literally be ran on a pc with nothing more then the OS.... and the application im trying to manipulate as it will be running most of the time.

many thanks :)

Post Reply