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.

Hex2Date

 Keywords: Hex Date YMDHMS Registry Convert Time UTC 

#DefineFunction HexByteToDec(_sHexByte)
_sHexByte = StrUpper(_sHexByte)
nHexOff = 55
nByte = 0
For i = 1 To 2
   cNybble = StrSub(_sHexByte,i,1)
   If !IsInt(cNybble) Then cNybble = Char2Num(cNybble) - nHexOff
   nByte = (nByte << 4) | cNybble
Next
Return nByte
#EndFunction

#DefineFunction Hex2Date(Hex)
aH = Arrayize(Hex," ")
If ArrInfo(aH,1)<8 Then Return ""
aD = ArrDimension(8)
For i = 0 To 7
   aD[i] = HexByteToDec(aH[i]) * 1.0
Next
Term = aD[7] * (2.0**56) + aD[6] * (2.0**48) + aD[5] * (2.0**40) + aD[4] * (2.0**32) + aD[3] * (2.0**24) + aD[2] * (2.0**16) + aD[1] * (2.0**8) + aD[0]
Days = Term / (1E7 * 86400)
fDate = 0.0 + ObjectType("DATE",Days) + ObjectType("DATE","1601/01/01")
Return ObjectType("DATE",fDate)
#EndFunction

; Test
RegShutdownTime = RegQueryBin(@REGMACHINE,"System\CurrentControlSet\Control\Windows[ShutdownTime]"); Sample '04 8B DA 6D 2B A4 C9 01'
ShutDownTime = Hex2Date(RegShutdownTime)
Message("",ShutDownTime:" GMT")
Exit

Article ID:   W18405
Filename:   Hex2Date.txt
File Created: 2009:03:16:09:13:28
Last Updated: 2009:03:16:09:13:28