Monday, November 5, 2007

Get UTC/GMT time in classic ASP

ASP doesn't have the .NET UtcNow() function, but you can easily make one. Code I found on google seemed overly complex for such a simple solution. this lets you get the server UTC time in classic ASP, it outputs the time in datetime format, and the function is conveniently named UtcNow so that if you wanted to transfer your code to later, it would already be taken care of. make sure you replace the brackets and put the javascript in the head.

[script language="JScript" runat="server"]
var serverdate=new Date();

Function UtcNow()
UtcNow = serverdate.toUTCString()
UtcNow = CDate(Replace(Right(UtcNow, Len(UtcNow) - Instr(UtcNow, ",")), "UTC", ""))
End Function


  1. Nice. Mixing JS and VBScript on the server side can be used to create some interesting stuff. Thanks.

  2. Thank you for posting this - it was a real timesaver.