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

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

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Date/Time Routines :: Can I get millisecond accuracy in ASP?


Can I get millisecond accuracy in ASP?

VBScript does not support such fine granularity within formatdatetime, datediff, or dateadd. 
 
But there may still be a way to do what you want, depending on your goal. 
 
If you want to count the number of milliseconds between two dates, there are very few scenarios where you could make this work in VBScript. Perhaps if two datetime values are stored in SQL Server, including milliseconds, and you retrieved them using a string... parsing it out and doing all the math yourself (yuck). If that were the case, you could just as easily do the DATEDIFF within SQL Server, and then you wouldn't have to do the math in VBScript. You can do this as follows: 
 
    SELECT numMs = CAST(DATEDIFF(MS, dt_1, dt_2) AS VARCHAR(32)) FROM <tbl> 
    -- or if you just want a datetime to display in ASP with milliseconds: 
    SELECT numMs = CAST(dt AS VARCHAR(32)) 
 
JScript does support a getMilliseconds() method, which gets the milliseconds from the current time: 
 
<script language=javascript runat=server> 
    var dt = new Date(); 
    var h = dt.getHours(), m = dt.getMinutes(); 
    var s = dt.getSeconds(), ms = dt.getMilliseconds(); 
    Response.Write(h + ":" + m + ":" + s + "." + ms); 
</script>
 
So it may be possible that you can use Jscript to get millisecond accuracy. Certainly if you define two dates within a script, and you want to know how many milliseconds passed between them, you can do custom math functions which will have to vary calculations depending on how many minutes, seconds etc. have elapsed. But the question is, how valuable is this information? 
 
If you have milliseconds stored in SQL Server, you can get these values to the ASP page simply by adding a DATEPART clause to your query, and returning it as a string. For example: 
 
    DECLARE @dt CHAR(23) 
    SET @dt = '2002-02-25 17:07:27.400' 
    CREATE TABLE #dt (d DATETIME) 
    INSERT #dt VALUES(@dt) 
    SELECT d, DATEPART(MS,d) FROM #dt 
    DROP TABLE #dt
 
Of course, once you get that value back to ASP, the greatest utility you will get from it is dumping it to the screen as text.

Related Articles

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 determine the number of seconds since 1/1/1970?
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: 1/23/2001 | Last Updated: 2/25/2002 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (359)

 

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