Customer Login  .   Webmail Login  .   About Us  .   Contact Us
Go to: Articles List

Date Manipulation Part 2 : Adding & Subtracting Dates & Times

VBScript provides developers with a wonderful function called DateAdd(). With this function you can add or subtract from a date or time.

DateAdd(PartOfDate, AmountToChange, Date)
- returns a date that has been changed the specified amount
- AmountToChange is the number to which you want the date to change (1, -4, 10, etc).
- Date is a valid date
- PartOfDate parameter can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

An example of what each of those values will output is:

var1 = Now()
Response.Write("var1 = " & var1 & "<br>")
Response.Write("var1 plus 10 days = " & DateAdd("d", 10, var1) & "<br>")
Response.Write("var1 minus 10 days = " & DateAdd("d", -10, var1) & "<br>")
Response.Write("var1 plus 3 months = " & DateAdd("m", 3, var1) & "<br>")
Response.Write("var1 minus 3 months = " & DateAdd("m", -3, var1) & "<br>")
Response.Write("var1 plus 2 hours = " & DateAdd("h", 2, var1) & "<br>")
Response.Write("var1 minus 2 hours = " & DateAdd("h", -2, var1) & "<br>")

Results:
var1 = 9/1/99 1:41:04 PM
var1 plus 10 days = 9/11/99 1:41:04 PM
var1 minus 10 days = 8/22/99 1:41:04 PM
var1 plus 3 months = 12/1/99 1:41:04 PM
var1 minus 3 months = 6/1/99 1:41:04 PM
var1 plus 2 hours = 9/1/99 3:41:04 PM
var1 minus 2 hours = 9/1/99 11:41:04 AM

Shared Hosting
Rookie
Pro
Advanced
Dedicated Servers
BASE
BUSINESS
ENTERPRISE
Why Choose Brinkster?
Radical Support
Brinkster Datacenter
Brinkster Network
Corporate Social Responsibility
90 Day Money Back Guarantee
Unsurpassed Value
Client Testimonials
Additional Features
Antivirus
Merchant Account
E-Commerce
Live Chat Communicator
Free Firewall
Website Builder
Free Web Hosting
Support
General Support
Codebank Search
Forums
Articles
Click here for Brinkster Live Chat
Home   Domains   Shared Hosting   Dedicated Hosting   Partner   Support   About Us    Contact Us   Webmail
Copyright © Brinkster Communications Corporation All Rights Reserved. Privacy Policy & Legal