Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript DateAdd Function

VBScript DateAdd Function


VBScript reference manual Complete VBScript Reference Manual


The DateAdd function returns a date to which a specified time interval has been added.

Syntax

DateAdd(interval,number,date)

Parameters Description
interval Required. The time interval you want to add.

The following values can be used:

  • yyyy - year
  • q - quarter
  • m - month
  • y - day of the year
  • d - day
  • w - day of the week
  • ww - week of the year
  • h - hour
  • n - minute
  • s - Seconds
  • | | number | Required. The number of time intervals to add. Use positive values for future dates and negative values for past dates. | | date | Required. The variable or literal representing the date to which the time interval is added. |

    Example

    Example 1

    How to use the parameters:

    The example above produces the following output:

    1/31/2011

    4/30/2010

    2/28/2010

    2/1/2010

    2/1/2010

    2/1/2010

    2/7/2010

    1/31/2010 9:50:00 AM

    1/31/2010 8:51:00 AM

    1/31/2010 8:50:01 AM

    Try it »

    Example 2

    Subtract one month from January 31, 2001:

    The example above produces the following output:

    12/31/2009

    Try it »

    Example 3

    Add one day to the current date:

    The example above produces the following output:

    document.write(DateAdd("d",1,Now()))

    Try it »


    VBScript reference manual Complete VBScript Reference Manual