BrainDump
  Home arrow BrainDump arrow Page 2 - VBScript: Final Date Functions
Iron Speed
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 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 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: Final Date Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-01

    Table of Contents:
  • VBScript: Final Date Functions
  • Here and Now
  • Time is Always Against Us
  • Timer...It Has Its Eye On You
  • The TimeValue() 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

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    VBScript: Final Date Functions - Here and Now
    (Page 2 of 5 )

    As we said before, the Now() function returns the current date and time, based on your system. If you wanted to display the current time for your user, then this is the function for you.


    <html>

    <body>

    <script type="text/vbscript">

    document.write(Now) &"<br />"

    </script>

    </body>

    </html>

    The result is (it will be different for you, as the time will change):

      1/29/2008 10:29:45 AM

    You can also perform math based on the Now() function and, as we've seen in prior articles, parse data from it. Here, in this example, we will subtract days, months, and even years from the current date and time:


    <html>

    <body>

    <script type="text/vbscript">

    document.write("The date and time is: ")&(Now) & "<br /> <br />"

    document.write("I was born on: ")&(Now-11239)& "<br /> <br />"

    document.write("A year ago the date was: ") & (Now-365) & "<br /> <br />"

    document.write("A month ago it was: ") & (Now-30) & "<br /> <br />"

    document.write("In ten years it will be: ") & (Now+3650)

    </script>

    </body>

    </html>

    This code results in:

      The date and time is: 1/29/2008 10:40:43 AM

      I was born on: 4/22/1977 10:40:43 AM

      A year ago the date was: 1/29/2007 10:40:43 AM

      A month ago it was: 12/30/2007 10:40:43 AM
     
      In ten years it will be: 1/26/2018 10:40:43 AM

    And here is how you can parse out the various increments of time:


    <html>

    <body>


    <script type="text/vbscript">

    document.write("The week of the year is: ")&(DatePart("ww",Now)) & "<br />"

    document.write("The day of the year is: ")&(DatePart("d",Now)) & "<br />"

    document.write("The year is: ")&(DatePart("YYYY",Now)) & "<br />"

    document.write("The weekday is: ")&(DatePart("w",Now)) & "<br />"

    document.write("The hour is: ")&(DatePart("H",Now)) & "<br />"

    document.write("The minute is: ")&(DatePart("n",Now)) & "<br />"

    document.write("The second is: ")&(DatePart("s",Now)) & "<br />"

    document.write("This is quarter: ")&(DatePart("q",Now))

    </script>

    </body>

    </html>

    Resulting in:

      The week of the year is: 5
      The day of the year is: 29
      The year is: 2008
      The weekday is: 3
      The hour is: 10
      The minute is: 52
      The second is: 21
      This is quarter: 1

    Again, this will have different values when you try it, as the time will be different.

    More BrainDump Articles
    More By James Payne


       · Thanks for stopping by to read another article. In this episode we discuss the last...
     

    BRAINDUMP ARTICLES

    - 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
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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