Saturday 16 June 2007

Convert UTC dates into 'normal' Dates

I recently had to import a Basecamp XML dump into a database and had muchos fun working with their UTC dates in the form 'Fri Sep 15 07:13:01 UTC 2006'. I don't know jack about date formats and so on but VBScript did not want to recognize these, nor did SQL Server.

Thus I came up with the following:

<script language="jscript" runat="server">
 
function TimestampFromUTC( sUTC ) {
  return Date.parse(sUTC) / 1000; // seconds rather than milliseconds
}
 
</script>
 
<script language="vbscript" runat="server">
 
Function DateFromTimestamp( iTimestamp )
  DateFromTimestamp = DateAdd( "s", iTimestamp, "01/01/1970 00:00:00" )
End Function
 
</script>

Usage: DateFromTimestamp( TimestampFromUTC( s ) )

No comments: