WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDF to Convert Time to Greenwich Standard Time

Keywords: 	  udf greenwich standard time

This function returns the current time converted to Greenwich Standard Time.
#Definefunction TimeYmdHmsGMT()
   Xbias = "System\CurrentControlSet\control\TimeZoneInformation[ActiveTimeBias]"
   offset = RegQueryDword(@REGMACHINE,Xbias)
   if offset<0 then val=timesubtract(timeymdhms(),strcat("0:0:0:0:",-offset,":0"))
   else val=timeadd(timeymdhms(),strcat("0:0:0:0:",offset,":0"))
   return val
#endfunction

Message("Val =",TimeYmdHmsGMT())
exit
This converts a GMT time into a timezone and adjusts for DST if needed. TimeZone is any string that matches a subkey name in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones\ Returns YYYY:MM:DD:HH:MM:SS DT/ST
#definefunction ConvertTimezone(GMT,TimeZone)
TZS=regopenkey(@regmachine,"SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones")
if !regexistkey(TZS,TimeZone) then TimeZone="GMT"
TZ=regopenkey(TZS,TimeZone)
Info=RegQueryBin(TZ,"[TZI]")
regclosekey(TZ)
regclosekey(TZS)

x1=ItemExtract(1,Info," ")
x2=ItemExtract(2,Info," ")
x3=ItemExtract(3,Info," ")
x4=ItemExtract(4,Info," ")
x1=xHex(x1)
x2=xHex(x2)
x3=xHex(x3)
x4=xHex(x4)
StandardBias= (x4 << 24) + (x3 << 16) + (x2 << 8) + x1

if StandardBias<0 then LocalStandardTime=timeadd(gmt,strcat("0:0:0:0:",-StandardBias,":0"))
else LocalStandardTime=timesubtract(gmt,strcat("0:0:0:0:",StandardBias,":0"))

LocalYear=itemextract(1,localstandardtime,":")


x1=ItemExtract(9,Info," ")
x2=ItemExtract(10,Info," ")
x3=ItemExtract(11,Info," ")
x4=ItemExtract(12,Info," ")
x1=xHex(x1)
x2=xHex(x2)
x3=xHex(x3)
x4=xHex(x4)
DaylightBias= (x4 << 24) + (x3 << 16) + (x2 << 8) + x1


MDaylightBegin=xHex(ItemExtract(31,Info," "))
if MDaylightBegin; conditional statement tells if that timezone practices DST at all
DDaylightBegin=xHex(ItemExtract(33,Info," "))
WDaylightBegin=xHex(ItemExtract(35,Info," "))
HDaylightBegin=xHex(ItemExtract(37,Info," "))

MDaylightBeginYMD=strcat(localyear,":",MDaylightBegin,":01:",HDaylightBegin,":0:0")

DOW=(7-(timejulianday(MDaylightBeginYMD)-2-DDaylightBegin) mod 7) mod 7
DaylightBeginYMD=timeadd(MDaylightBeginYMD,strcat("0:0:",dow,":0:0:0"))

for n=2 to WDaylightBegin
	nextweek=timeadd(DaylightBeginYMD,"0:0:7:0:0:0")
	if itemextract(2,nextweek,":")-MDaylightBegin then break
	DaylightBeginYMD=nextweek
next


MDaylightEnd=xHex(ItemExtract(15,Info," "))
DDaylightEnd=xHex(ItemExtract(17,Info," "))
WDaylightEnd=xHex(ItemExtract(19,Info," "))
HDaylightEnd=xHex(ItemExtract(21,Info," "))

MDaylightEndYMD=strcat(localyear,":",MDaylightEnd,":01:",HDaylightEnd,":0:0")

DOW=(7-(timejulianday(MDaylightEndYMD)-2-DDaylightEnd) mod 7) mod 7
DaylightEndYMD=timeadd(MDaylightEndYMD,strcat("0:0:",dow,":0:0:0"))

for n=2 to WDaylightEnd
	nextweek=timeadd(DaylightEndYMD,"0:0:7:0:0:0")
	if itemextract(2,nextweek,":")-MDaylightEnd then break
	DaylightEndYMD=nextweek
next

if DaylightBias<0 then DaylightEndYMD=timesubtract(DaylightEndYMD,strcat("0:0:0:0:",-DaylightBias,":0"))
else DaylightEndYMD=timeadd(DaylightEndYMD,strcat("0:0:0:0:",DaylightBias,":0"))

afterbegin=timediffSecs(LocalStandardTime,DaylightBeginYMD)
afterend=timediffSecs(LocalStandardTime,DaylightEndYMD)

;this answers the BIG QUESTION: is that timezone in DST????
DST=(((afterbegin>afterend)-0.5)*((afterend>=0)-0.5)*((afterbegin>=0)-0.5))<0

else
DST=0
endif

if dst
if DaylightBias<0 then LocalTime=timeadd(LocalStandardTime,strcat("0:0:0:0:",-DaylightBias,":0"))
else LocalTime=timesubtract(LocalStandardTime,strcat("0:0:0:0:",DaylightBias,":0"))
Localtime=strcat(localtime," DT")
else
LocalTime=strcat(LocalStandardTime," ST")
endif
return localtime
#endfunction 

Article ID:   W15767
File Created: 2006:10:16:08:26:20
Last Updated: 2006:10:16:08:26:20