faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems : Times/Dates

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

46 of 50 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I subtract a day from a Date?

May 3rd, 2001 12:08
Suzanne L., Gamini Jayarathne, Que's 'Using Visual Basic 4'


To subtract days from a date, use the DateAdd function with a negative 
number for the second argument.  


Que's 'Using Visual Basic 4' states:  (I confirmed it works in VBScript)

The DateAdd function is used as follows:

    newdate = DateAdd(interval, numintervals, olddate)

newdate and olddate represent date variables in the equation.  olddate 
can also be a literal date or a function that returns a date.  interval 
is a string expression defining the type of time period to be applied.  
numintervals specifies the number of time periods added to or 
subtracted from olddate.  If numintervals is positive, the time 
intervals are added to the olddate.  If numintervals is negative, the 
time intervals are subtracted from olddate.


FYI: interval values are as follows:
   "q"     Quarters
   "m"     Months
   "w"     Weekdays of the same day
   "d"     Days
   "h"     Hours
   "n"     Minutes
   "s"     Seconds



Example:

To remove one day from the current date (to get yesterday's date):

  Dim Yesterday
  Yesterday = DateAdd("d",-1,Date)



© 1999-2004 Synop Pty Ltd