📄 vbs90.htm
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML><HEAD><TITLE>DateAdd Function</TITLE>
<META NAME="CATEGORY" CONTENT="Language Reference">
<META HTTP-EQUIV="Content Type" CONTENT="text/html; charset=us-ascii">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="CHARSET" CONTENT="us-ascii">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT="DateAdd Function"></HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft® Visual Basic® Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>DateAdd Function</B></FONT>
</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2> <A HREF="vbstoc.htm">Language Reference</A> <BR>
<A HREF="vbs16.htm">Version 2</A> <P></FONT>
</TD></TR>
</TABLE>
<FONT SIZE=2><P>
<A HREF="vbs91.htm">See Also</A></FONT>
<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>
Returns a date to which a specified time interval has been added.
</BLOCKQUOTE>
<H5>Syntax</H5>
<BLOCKQUOTE>
<b>DateAdd(</b><i>interval</i><B>, </B><i>number</i><B>, </B><i>date</i><b>)</b><P>
The <b>DateAdd</b> function syntax has these parts:<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Part</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>interval</i></FONT></TD>
<TD><FONT SIZE=2>Required. <A HREF="vbs0.htm#defStringExpression">String expression</A> that is the interval you want to add. See Settings section for values.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>number</i></FONT></TD>
<TD><FONT SIZE=2>Required. <A HREF="vbs0.htm#defdefNumericExpression">Numeric expression</A> that is the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>date</i></FONT></TD>
<TD><FONT SIZE=2>Required. <B>Variant</B> or literal representing the date to which <i>interval</i> is added.</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>
<H5>Settings</H5>
<BLOCKQUOTE>
The <i>interval</i> argument can have the following values:<p>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD width=15%><FONT SIZE=2><b>Setting</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>yyyy</i></FONT></TD>
<TD><FONT SIZE=2>Year</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>q</i></FONT></TD>
<TD><FONT SIZE=2>Quarter</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>m</i></FONT></TD>
<TD><FONT SIZE=2>Month</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>y</i></FONT></TD>
<TD><FONT SIZE=2>Day of year</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>d</i></FONT></TD>
<TD><FONT SIZE=2>Day</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>w</i></FONT></TD>
<TD><FONT SIZE=2>Weekday</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>ww</i></FONT></TD>
<TD><FONT SIZE=2>Week of year</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>h</i></FONT></TD>
<TD><FONT SIZE=2>Hour</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>n</i></FONT></TD>
<TD><FONT SIZE=2>Minute</FONT></TD></TR>
<TR VALIGN=TOP>
<TD width=15%><FONT SIZE=2><i>s</i></FONT></TD>
<TD><FONT SIZE=2>Second</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>
<H5>Remarks</H5>
<BLOCKQUOTE>
You can use the <b>DateAdd</b> function to add or subtract a specified time interval from a date. For example, you can use <b>DateAdd</b> to calculate a date 30 days from today or a time 45 minutes from now. To add days to <I>date</I>, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").<p>
The <b>DateAdd</b> function won't return an invalid date. The following example adds one month to January 31:<P>
<BLOCKQUOTE><PRE><font face="Courier New" SIZE=3>NewDate = <FONT COLOR=#FF0000>DateAdd(</FONT>"m"<FONT COLOR=#FF0000>, </font>1<FONT COLOR=#FF0000>, </font>"31-Jan-95"<FONT COLOR=#FF0000>)</font></font>
</PRE></BLOCKQUOTE>
In this case, <b>DateAdd</b> returns 28-Feb-95, not 31-Feb-95. If <I>date</I> is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.<p>
If the calculated date would precede the year 100, an error occurs.<p>
If number isn't a <B>Long</B> value, it is rounded to the nearest whole number before being evaluated.
</BLOCKQUOTE>
<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">© 1997 by Microsoft Corporation. All rights reserved.</a></em></p>
</FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -