need function to turn clock back by 3 hours

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MCP
Posts: 2
Joined: 31 Mar 2016 06:40

need function to turn clock back by 3 hours

#1 Post by MCP » 31 Mar 2016 07:25

Hope someone can help with this. I am looking for a function I can use in a Windows batch file that will turn the clock back 3 hours from its "current" setting.

Here are the requirements I foresee:
- parse the "current" time (i.e. 2:42 PM)
- calculate "current" time minus 3 hours (i.e. 11:42 AM if current time as 2:42 PM) and set that value as "new time"
- Change the "current time" to "new time".
- account for rolling back the date by a day if the time change would set it a time on previous day (i.e. Rolling back if the current time is between 12 am and 3 am requires changing the date back a day as well)

Thanks,
Mike

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need function to turn clock back by 3 hours

#2 Post by foxidrive » 31 Mar 2016 08:20

Can I ask what the purpose is for this task?

MCP
Posts: 2
Joined: 31 Mar 2016 06:40

Re: need function to turn clock back by 3 hours

#3 Post by MCP » 31 Mar 2016 10:29

Here is the background: I have a batch file that customizes newly installed copies of the Windows OS. Part of the batch file sets the timezone to EST. When this happens it advances the clock by 3 hours because Windows defaults to PST. Before you say anything; I know I could develop an automated install of Windows that uses the correct timezone. At this time though I'm not ready to do that so I just want to address this issue through batch file. Thats the purpose of the request.

Mike

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need function to turn clock back by 3 hours

#4 Post by foxidrive » 01 Apr 2016 04:55

Have a look at a batch script called GetTimeStamp.bat written by dbenham
viewtopic.php?p=44148#p44148

It has 7 billion methods of calculating time/date

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: need function to turn clock back by 3 hours

#5 Post by dbenham » 01 Apr 2016 11:44

MCP wrote:Foxidrive,
Thanks for the link. I'm sure someone could probably use that script to code part of what I'm trying to accomplish but for me it is beyond my current experience level to understand it and then write the additional code required to use it in the way I need in any kind of timely manner.

I'm really looking for something a bit more "turn key" that I can just copy and plug-in to my batch file. If you have any additional examples that are a little closer to my requirements or can put together something that specifically targets what I need then that would be fantastic.

Mike

It doesn't get much more turnkey than getTimestamp.bat.

You need to know the date and time format used by your locale. For me I need mm-dd-yyyy and hh:mm:ss.ff, where hh is in 24 hour format, and .ff is optional fractional seconds. Also, you must be running as administrator if you want to modify your computer's system date/time.

Code: Select all

for /f "tokens=1,2" %%A in (
  'gettimestamp /oh -3 /f "{mm}-{dd}-{yyyy} {hh}:{nn}:{ss}"'
) do date %%A & time %%B


Dave Benham

Post Reply