Creating UNIX Time in Windows Script

I recently found myself needing to convert a date/time in a Windows vbs script to UNIX time and struggled to find an example of how to do this. Correct me if I’m wrong, but there doesn’t seem to be any built-in function to change 20070109161723+720 to 1168359443.

After fine-tuning a few Google queries I found using the DateDiff function the easiest way and came up with,

Function WMIDateToUNIX(strDate)
ConvertedDate = CDate(Mid(strDate, 7, 2) & "/" & _
Mid(strDate, 5, 2) & "/" & Left(strDate, 4) _
& " " & Mid (strDate, 9, 2) & ":" & _
Mid(strDate, 11, 2) & ":" & Mid(strDate,13, 2))

WMIDateToUNIX = DateDiff(“s”, “01/01/1970 00:00:00”,ConvertedDate)
End Function

Not the prettiest code I’ll admit, but if someone else can use it that’s all well and good.

Leave a Reply

Your email address will not be published. Required fields are marked *