Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Understanding Dates and Times in VBScript
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Understanding Dates and Times in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2009-01-12

    Table of Contents:
  • Understanding Dates and Times in VBScript
  • VBScript’s VT_DATE Specification
  • The Significance of 30 Dec 1899
  • Using the VT_Time Specification

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Understanding Dates and Times in VBScript - VBScript’s VT_DATE Specification


    (Page 2 of 4 )

    Microsoft Visual Basic Scripting Edition uses the VT_DATE specification for working with date and time values.  This is a Variant Date type that uses a 64-bit (8 bytes) signed floating point number to represent the number of days that have passed since midnight on a specific day in history, known as an epoch.  Hours and minutes are expressed as fractions of a day.

    “A specific day in history?”

    Yup.  Okay, that was a little vague.  The VT_Date specification expresses the number of days that have passed since 30 Dec 1899.

    “Why that day?”

    This is one of those things that is believed to be a bug, but really isn’t.  To explain it, you need to become familiar with the standard, so let’s look at some examples.

    Let’s assume for once second that the epoch was midnight 31 Dec 2007 instead.  As I’m writing this, the current date is 1 Sep 2008.  That means that 244 days have elapsed since the epoch day.  Further, it’s 3:25 PM.  That’s 15 hours and 25 minutes, or 925 minutes that have elapsed since midnight.

    We can express today’s date and time as a floating point number like VT_Date.  The integer portion of the number is the number of days that have elapsed since the epoch day.  There are 244 days that have elapsed.  That makes the integer portion equal to 244.

    The time is expressed as a decimal fraction of a day.  We’ve already shown that 925 minutes have elapsed since midnight.  There are 1440 minutes in a day.  Simple division shows that 0.642361 days have passed since midnight.  Sure enough, at 3:25 PM that’s just about two-thirds of a day.

    With all of this in mind, the current date and time would look something like this: 244.642361 if we were using midnight on 30 Dec 2007 as our zero point.  This is exactly how the VT_Date specification works—only it works with a zero point much further back in time.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek