Skip to content

Instantly share code, notes, and snippets.

@badursun
Forked from radleta/DateTimeConvert.asp
Created January 24, 2022 09:24
Show Gist options
  • Save badursun/72398f8005fc080d0a9904560ec4815b to your computer and use it in GitHub Desktop.
Save badursun/72398f8005fc080d0a9904560ec4815b to your computer and use it in GitHub Desktop.
Date and Time conversion local to and from UTC for ASP.
<%
' ****************************************************************************
' Sub: GetUtcOffsetMinutes
' Description: Gets the number of minutes between local time and UTC.
'
' Params: None
' ****************************************************************************
Function GetUtcOffsetMinutes()
Dim key
key = "UtcOffsetMinutes"
GetUtcOffsetMinutes = Application(key)
If IsEmpty(GetUtcOffsetMinutes) Then
'Create Shell object to read registry
Dim oShell, atb, offsetMinutes
Set oShell = CreateObject("WScript.Shell")
'Reading the registry
GetUtcOffsetMinutes = oShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
Application(key) = GetUtcOffsetMinutes
Set oShell = Nothing
End If
End Function
' ****************************************************************************
' Sub: ConvertToUtcTime
' Description: Converts the local time to UTC time.
'
' Params: localDateTime: The local time to convert to UTC time.
' ****************************************************************************
Function ConvertToUtcTime(localDateTime)
ConvertToUtcTime = DATEADD("n", GetUtcOffsetMinutes(), localDateTime)
End Function
' ****************************************************************************
' Sub: ConvertToLocalTime
' Description: Converts the UTC time to local time.
'
' Params: utcDateTime: The UTC time to convert to local time.
' ****************************************************************************
Function ConvertToLocalTime(utcDateTime)
ConvertToLocalTime = DATEADD("n", -(GetUtcOffsetMinutes()), utcDateTime)
End Function
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment