Solved

Batch File: Fix date and time with Time Zone

Posted on 2014-01-10
7
1,402 Views
Last Modified: 2014-01-10
Hi there,

I have a date, and a time at 0GMT.

To need a batch file to change them according to -5GMT

For example:
2014-01-10 00:44:34  -> 2014-01-09 19:44:34
2014-02-01 00:44:34 -> 2014-01-31 19:44:34
2014-02-01 20:44:34 -> 2014-02-01 15:44:34

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:CorinTack
ID: 39771522
Add the following to a batch file:

TZUTIL /s "Eastern Standard Time"
0
 
LVL 10

Author Comment

by:ReneGe
ID: 39771552
hey CorinTack, thank for your prompt reply.

I don't need to change the time zone of my PC.

For example:

@ECHO OFF
CALL :TimeZone "2014-01-10 00:44:34"
ECHO %NewDate% %NewTime%
PAUSE
EXIT

:TimeZone
REM Code nere
EXIT /b
0
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39772103
You might think of this as "cheating" but it's a very useful approach in BAT scripts.

@echo off
REM Initialization
echo d=DateAdd("h",CInt(Wscript.Arguments.Item(1)),CDate(Wscript.Arguments.Item(0)))>"%TEMP%\_t.vbs"
echo Wscript.Echo Year(d)^&"-"^&Right("0"^&Month(d),2)^&"-"^&Right("0"^&Day(d),2)^&" "^&Right("0"^&Hour(d),2)^&":"^&Right("0"^&Minute(d),2)^&":"^&Right("0"^&Second(d),2)>>"%TEMP%\_t.vbs"

REM Main logic
call :tzAdjust "2014-01-10 00:44:34" "-5"
echo Expected: 2014-01-09 19:44:34
echo tzAdjust: %tzAdjust%
echo.
call :tzAdjust "2014-02-01 00:44:34" "-5"
echo Expected: 2014-01-31 19:44:34
echo tzAdjust: %tzAdjust%
echo.
call :tzAdjust "2014-02-01 20:44:34" "-5"
echo Expected: 2014-02-01 15:44:34
echo tzAdjust: %tzAdjust%

REM Cleanup
del "%TEMP%\_t.vbs"
exit /b

:tzAdjust [date-time] [hours-offset]
  for /F "tokens=*" %%A in ('cscript //nologo "%TEMP%\_t.vbs" "%~1" "%~2"') do set tzAdjust=%%A
  exit /b

Open in new window

~bp
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 10

Author Comment

by:ReneGe
ID: 39772207
Hey buddy, its been a while :)

here is my output:
Expected: 2014-01-09 19:44:34
tzAdjust: 2014-01-09 19:44:34

Expected: 2014-01-31 19:44:34
tzAdjust: 2014-01-31 19:44:34

Expected: 2014-02-01 15:44:34
tzAdjust: 2014-02-01 15:44:34

Cheers
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 39772746
Correct, that's the proper output, as you requested.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 39772813
Whats wrong with me???

Thanks Bill :)
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 39772866
Welcome Rene.

~bp
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question