SunQuest
 
       BrainDump
  Home arrow BrainDump arrow Page 3 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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: 5 stars5 stars5 stars5 stars5 stars / 3
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    VBScript Date Functions - Working with the Date Function


    (Page 3 of 4 )

    If you want to print out the date according to your current system time, you can do so in this exciting manner:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("The Date is: ")

    document.write(Date)

    </script>

    </body>

    </html>

    We can also form calculations with the Date function:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("The Date minus one day is: ")

    document.write(Date -1 & "<p> </p>")

    document.write("The Date minus a year is: ")

    document.write(Date -365)

    </script>

    </body>

    </html>

    This results in:

      The Date minus one day is: 12/3/2007

      The Date minus a year is: 12/4/2006

    Of course if we really want to perform math on dates, we should use the DateAdd function.

    Adding Dates

    To perform math on dates, it is best to use the DateAdd function. The syntax of the function is: DateAdd(interval,number,date). There are several parameters that you can work with:

    • yyyy: Used for year

    • q: Used for quarter

    • m: Used for month

    • y: Used for day of the year

    • d: Used for day

    • w: Used for weekday

    • ww: Used for week of year

    • h: Used for hour

    • n: used for minute

    • s: Used for second


    Here are some examples:

    Adding a month to today's date:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("Today's date plus a month is: ")

    document.write(DateAdd("m",1,date))

    </script>


    </body>

    </html>

    Adding Five Years to Today's Date:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("Today's date plus five years is: ")

    document.write(DateAdd("yyyy",5,date))

    </script>

    </body>

    </html>

    Adding Five Years to Any Date I Specify OR Making Myself Feel Old


    <html>

    <body>

    <script type="text/vbscript">

    document.write(DateAdd("yyyy",30,"22-April-1977"))

    </script>

    </body>

    </html>

    Subtracting 20 Days from A Date


    <html>

    <body>

    <script type="text/vbscript">

    document.write(DateAdd("d",-20,"22-04-1977"))

    </script>

    </body>

    </html>

    More BrainDump Articles
    More By James Payne


       · Thanks for stopping by. In this article we discuss Date Functions in VBScript, like...
     

    BRAINDUMP ARTICLES

    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway