Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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 - The Significance of 30 Dec 1899


    (Page 3 of 4 )

    Okay, so back to the question at hand.  Why 30 Dec 1899.  Why not 1 Jan, 1900 to make calculations easier?  And what happened to 31 Dec 1899?  It makes no sense.  Or does it?

    The idea was originally to simplify calculations by using the beginning of the century as a zero point on the time line.  This would have been midnight on 31 Dec 1899, thus the very first second that elapsed would have been on 1 Jan 1900, making it the very first second of the century, also making 1 Jan 1900 the first full day.  This seems like a very logical solution.  Unfortunately, human logic and computer logic aren’t always the same.

    The date functions in VBScript (and originally Visual Basic) were largely taken from Microsoft Excel which already had a large set of built-in date functions.  Why reinvent the wheel?

    There’s just one small problem.  If you examine the Excel functions that were used, you’ll run into a slight glitch.  January 1, 1900 is considered 1, the first full day.  The functions also show that February 28, 1900 is equal to 59.  And it’s true that 59 days had elapsed.  Great.  If you tried March 1, 1900 as a date it would return 61.  Uh-oh.

    What happened to 60?  February 29, 1900?  There’s one minor problem—the year 1900 was not a leap year.  How could the Excel guys have missed that?  The truth is that they didn’t.  It was an imported bug.  Literally!

    Excel was written with support for importing from Lotus 123, which displayed this bug.  In order to support imported dates, Excel needed to calculate them the same way.  The truth is that this was probably an intended bug in Lotus.  It had memory constraints, so it uses a simplified method of determining whether or not a particular year was a leap year.  The Lotus team probably wasn’t too worried about being wrong about the first two months of a year so long ago.

    The VB team was; so rather than starting from January 1, 1900, they elected to make calculations from the previous year by moving the epoch back one day to December 31, 1899 instead.  Thus the starting point for time became midnight of December 30, 1899.

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek