Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

VBScript DateAdd 函数

❮ VBScript 全面参考

DateAdd 函数返回添加了指定时间间隔的日期。

语法

DateAdd(interval, number, date)
参数 描述
interval 必需。要添加的间隔。

可以取以下值:

  • yyyy - 年
  • q - 季度
  • m - 月
  • y - 年中的日期
  • d - 日
  • w - 星期几
  • ww - 一年中的星期
  • h - 小时
  • n - 分钟
  • s - 秒
number 必需。要添加的间隔数。可以是正数(表示将来的日期)或负数(表示过去的日期)。
date 必需。表示要添加间隔的日期的变体或字面量。

示例

示例 1

如何使用参数

<%

response.write(DateAdd("yyyy",1,"31-Jan-10") & "<br />")
response.write(DateAdd("q",1,"31-Jan-10") & "<br />")
response.write(DateAdd("m",1,"31-Jan-10") & "<br />")
response.write(DateAdd("y",1,"31-Jan-10") & "<br />")
response.write(DateAdd("d",1,"31-Jan-10") & "<br />")
response.write(DateAdd("w",1,"31-Jan-10") & "<br />")
response.write(DateAdd("ww",1,"31-Jan-10") & "<br />")
response.write(DateAdd("h",1,"31-Jan-10 08:50:00") & "<br />")
response.write(DateAdd("n",1,"31-Jan-10 08:50:00") & "<br />")
response.write(DateAdd("s",1,"31-Jan-10 08:50:00") & "<br />")

%>

上面代码的输出将是

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
显示示例 »

示例 2

从 2010 年 1 月 31 日减去一个月

<%

response.write(DateAdd("m",-1,"31-Jan-10"))

%>

上面代码的输出将是

12/31/2009
显示示例 »

示例 3

从现在添加一天

<%

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

%>

上面代码的输出将是

10/10/2024 4:29:26 PM
显示示例 »

❮ VBScript 全面参考
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.