//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
ASP FAQ Tutorials

   8000XXXX Errors
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map



ASP FAQ Tutorials :: Classic ASP 1.0 :: Date/Time Routines :: How do I determine the number of seconds since 1/1/1970?

How do I determine the number of seconds since 1/1/1970?

This is a pretty common one, as many systems use this measure for various date calculations. Here are examples in VBScript, JScript and Transact-SQL. Note that to get the number of milliseconds since 1/1/1970, you need to multiply these results by 1000.  
        timeStart = "1/1/1970 12:00:00 AM" 
        Response.Write(datediff("s", timeStart, now())) 
JScript - we need to correct for UTC, which is already accounted for.
    <script language='jscript' runat=server> 
        var timeStart = new Date(); 
        var tz = timeStart.getTimezoneOffset()*60*1000; 
        timeStart = Math.floor(((timeStart.getTime() - tz))/1000); 
    SELECT DATEDIFF(SECOND, '1/1/1970 12:00:00 AM', GETDATE())
Note also that these solutions do not account for leap seconds. You can add them in manually for leap seconds that have been known to occur in the past (06/30/1997 and 12/31/1998 are two examples). You can not predict them programmatically... since leap seconds are defined by the variability of the Earth's rotation, and are declared by the International Earth Rotation Service as required. See this Google posting and this U.S. Navy article for highly detailed information about leap seconds and how they affect UTC. After reading these, you may see why your calculations don't need to be this precise -- especially since your web and/or SQL Server are probably not set to atomic clocks anyway. :-)

Related Articles

Can I get millisecond accuracy in ASP?
Can I make VBScript format dates for me?
Could I get a little help with dates?
Given a date, how do I find the beginning and end of that week?
Given two dates, how do I determine an age?
How do I calculate dates, such as the first day of the month?
How do I convert a DATEDIFF to days, hours, and minutes?
How do I convert a timespan, in seconds, to HH:MM:SS?
How do I convert local time to UTC (GMT) time?
How do I count the number of business days between two dates?
How do I delimit/format dates for database entry?
How do I display time in military format?
How do I implement a calendar / datepicker in ASP?
How do I select time only from a DATETIME column?
Why do I have problems inserting NOW() into a database?
Why does JavaScript's document.lastModified() not work in ASP files?



Created: 11/12/2001 | Last Updated: 11/12/2001 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (362)


Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...