d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help On Save Change Return A Date On A Pc
Add Reply New Topic New Poll
Member
Posts: 2,354
Joined: Dec 9 2014
Gold: 0.00
Apr 9 2017 08:04am
Im trying to write a cmd/batch or an auto it script to do the following

Save current date
Change date to specific date
Run a program on my pc
Change date back to saved current date
exit

What I got down so far:
cmd/batch
Code
i don't know how to save a date on cmd/bath
date ##/##/###
run
i need a way to change back to the saved date because this will be a program that will be ran every day
exit


autoit:
Code
$nowdate = _nowdate()
i dont know how to change a date in autoit or understand how to do it
run a program
and again i don't know how to change it or set it back to the saved variable

i can pay fg if needed
thanks for your help


This post was edited by AlvinHu on Apr 9 2017 08:06am
Member
Posts: 2,354
Joined: Dec 9 2014
Gold: 0.00
Apr 9 2017 08:55am
is there a way to save it without saving the time
i dont want the time to be changed at all

i looked through autoit already

so i thought about using _NowDate()
but I don't know if i can change it with _NowDate()

This post was edited by AlvinHu on Apr 9 2017 08:57am
Member
Posts: 5,627
Joined: Apr 13 2006
Gold: 390.00
Apr 9 2017 09:24am
Quote (AlvinHu @ Apr 9 2017 08:55am)
is there a way to save it without saving the time
i dont want the time to be changed at all

i looked through autoit already

so i thought about using _NowDate()
but I don't know if i can change it with _NowDate()


Blah I was trying to be quick and wasn't really paying attention. Looks like you could use the functions below to get the current time and set it when generating the new date.

https://www.autoitscript.com/autoit3/docs/libfunctions/_Now.htm

https://www.autoitscript.com/autoit3/docs/libfunctions/_NowTime.htm

https://www.autoitscript.com/autoit3/docs/macros/TimeAndDate.htm

This post was edited by SilverMice on Apr 9 2017 09:32am
Member
Posts: 2,354
Joined: Dec 9 2014
Gold: 0.00
Apr 9 2017 09:45am
can you write me a small example
my brain isnt working
Member
Posts: 5,627
Joined: Apr 13 2006
Gold: 390.00
Apr 9 2017 11:14am
Quote (AlvinHu @ Apr 9 2017 09:45am)
can you write me a small example
my brain isnt working


In the code below $tNew should result in the current day and time. You can change @MDAY or @MON or @YEAR to what ever value you want in order to achieve the date you are looking for.

Code
; Set new system time
$tNew = _Date_Time_EncodeSystemTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)


This post was edited by SilverMice on Apr 9 2017 11:17am
Member
Posts: 2,354
Joined: Dec 9 2014
Gold: 0.00
Apr 9 2017 03:24pm
Ok so this is what I did so far

Quote
#include <Date.au3>
#include <WindowsConstants.au3>

$tCur = _Date_Time_GetSystemTime() ; Get current system time
$tNew = _Date_Time_EncodeSystemTime(1, 1, 2017, @HOUR, @MIN, @SEC) ; Set new system time
Sleep(10000)
_Date_Time_SetSystemTime($tCur) ; Restore system time


So basically this should save current date
change date to 1/1/2017
delay 10seconds
then restore back to saved date

but when i ran a test script, the script didn't change my system date at all
am i doing something wrong on the script or is it a permission setting i need to change?

i've ran it as admin also already


This post was edited by AlvinHu on Apr 9 2017 03:25pm
Member
Posts: 5,627
Joined: Apr 13 2006
Gold: 390.00
Apr 10 2017 01:22pm
You never call _Date_Time_SetSystemTime with $tNew, you only call it with $tCur.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll