BrainDump
  Home arrow BrainDump arrow Page 4 - VBScript Date Functions
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? 
BRAINDUMP

VBScript Date Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-01-07

    Table of Contents:
  • VBScript Date Functions
  • Functioning it Up with CDate
  • Working with the Date Function
  • The Vainglorious DateDiff Function

  • 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


    VBScript Date Functions - The Vainglorious DateDiff Function


    (Page 4 of 4 )

    In the following example I created a program to tell the amount of years, months, minutes, and seconds since my birth:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("Today's date is: " & Date & "<br />")

    document.write("<br />The amount of time since my magnanimous birth can be measured in the following ways: <br /><br />")

    document.write(DateDiff("yyyy",Date,"04/22/1977")& (" years") & "<br />")

    document.write(DateDiff("m",Date,"04/22/1977")& (" months") & "<br />")

    document.write(DateDiff("n",Date,"04/22/1977")& (" minutes") & "<br />")

    document.write(DateDiff("s",Date,"04/22/1977")& (" seconds"))

    </script>

    </body>

    </html>

    The result is:

      Today's date is: 12/4/2007

      The amount of time since my magnanimous birth can be measured in the following ways:

      -30 years
      -368 months
      -16103520 minutes
      -966211200 seconds

    In the above example we calculated how much time had passed by subtracting my birthdate from the current time (well, based on our system timer). But what if I wanted to subtract a specified date from another specified date? I could do this:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("Today's date is: " & Date & "<br />")

    document.write("If Jesus had lived to be a hundred ")

    document.write("the difference in the date of his hundredth ")

    document.write("birthday and my birthdate could be ")

    document.write("measured thusly:<br /><br/>")

    document.write(DateDiff("yyyy","12/25/100","04/25/1977")& (" years") & "<br />")

    document.write(DateDiff("m","12/25/100","04/22/1977")& (" months") & "<br />")

    document.write(DateDiff("n","12/25/100","04/22/1977")& (" minutes") & "<br />")

    document.write(DateDiff("s","12/25/100","04/22/1977")& (" seconds"))

    </script>

    </body>

    </html>

    This results in the following:

      Today's date is: 12/4/2007
      If Jesus had lived to be a hundred the difference in the date of his hundredth birthday and my birthdate could be measured thusly:

      1877 years
      22516 months
      986850720 minutes
      59211043200 seconds

    You will note that I used the year 100. My original intention was to use the date 12/25/0000 (I know Jesus wasn't REALLY born on that day) but if you use anything less than 100 for the year portion of the date, computers get confused and think you are referencing the 1900s. Crazy computers. Then the next thing you know you got yourself a whole Stephen-King-Maximum-OverDrive meets Y2k situation on your hands. And that can't be good. Unless you're Stephen King and making Stephen King's money ($65 million a year!).

    Well that's all the time we have for this bad boy. Come back soon as I continue talking about Date Functions in VBScript.

    Till then...


    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.

       · Thanks for stopping by. In this article we discuss Date Functions in VBScript, like...
       · Need a printer-friendly version of the page!
     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT