Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - 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 - Using the VT_Time Specification


    (Page 4 of 4 )

    As I stated previously, the VT_Time Specification represents dates and times using a 64-bit (8 bytes) signed floating point number.  Because it is signed, the value may be positive or negative.  VBScript has two numeric data types that fit this specification: Date and Double.  Date was obviously created for this purpose.  VBScript handles values of type Date in a way that allows you to display dates very easily.  The numeric type Double can be used to display the actual 64-bit signed floating point number.

    By default, Dates in VBScript will be displayed using the local short-date format.  This is based on the local system settings.

    VBScript supports any date between 1 Jan 100 AD and December 31, 9999 AD.  In other words, it supports decimal values between -657434.000000 and 2958465.000000.  These constraints were used for two reasons.  First, this is pushing the limits available by the Double width, and second, because values less than 100 AD have a two digit year.

    Attempting to use dates outside of the valid range will result in an error.  Unfortunately, this error varies depending upon how this occurred.  This makes debugging slightly difficult.  My best advice: any date read from the system should be valid, but you should validate any date entered by a user before attempting to assign it to a date variable or function.

    In the twentieth century, the MM/DD/YY date format was acceptable.  Thus VBScript will accept two digits years, but it does assume that they occur between the years 1900 and 1999.  Since this can provide unpredictable results, it’s best to always use four digit years.

    VBScript dates are also considered to be local time.  This means that they are calculated using the local Region and Time Settings.  In other words, there is no inherent support for different time zones.  Times are calculated based on the system’s current time zone.  From a programming standpoint, this can be troublesome.  Thus, any code that involves events occurring in separate time zones will need to have additional logic to handle the time zone changes.

    For more detailed information about the shortcomings of VBScript’s dates and times, check out Eric Lippert’s blog on MSDN.

    Now that you have an understanding of how dates and times are handled by VBScript, you’re ready to begin working with them in your code.  In my next article, I’ll show you the various date and time functions available in VBScript.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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