title: Convert Time to UTC vbScript
body: <p>I have the following function which does fine at converting current time to UTC time. </p>
  
  <pre><code>Function toUtc(byVal dDate)
      Dim oShell : Set oShell = CreateObject("WScript.Shell")
      toUtc = dateadd("n", oShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"), cDate(dDate))
  End Function
  </code></pre>
  
  <p>However, I am thinking that this does not adequately handle conversion of future or historical dates to UTC, since the function would need to know the offset of the server's timezone at the time of the date that is being converted, and whether or not it was during daylight savings time or not. </p>
  
  <p>How can I get around this?</p>
  
  <p>I am using vbScript/Classic ASP on windows server with IIS7.5</p>
  
  <p>To clarify, this has nothing to do with formatting the date. It is all about converting to UTC from the server timezone for historical dates. During Daylight savings time, the offset will be off by 60 minutes if I try to convert a datetime which occurred in standard time.</p>
  
  <p>For example:</p>
  
  <p>Lets say that today, 2013-02-19 (non daylight-savings time), I want to covert a timestamp from say, 2008-06-05 (during daylight savings period) from PDT (my server timezone) to UTC. using the method in my function will give me a value which is 60 minutes off from the correct value (because the CURRENT time is PST (not PDT), the offset will be incorrect for that historical date).</p>
  
  <p>In other words, the timezone offset of the input date could be UTC-7 or UTC-8 depending on whether or not DST was observed on that particular date. I need to calculate the correct UTC date for the input date and I need the code to work whether or not DST is observed on current date.</p>