此函数返回两个指定时间间隔之间的差。
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> fromDate = "01-Jan-09 00:00:00" toDate = "01-Jan-10 23:59:00" document.write("Line 1 : " &DateDiff("yyyy",fromDate,toDate) & "<br />") document.write("Line 2 : " &DateDiff("q",fromDate,toDate) & "<br />") document.write("Line 3 : " &DateDiff("m",fromDate,toDate) & "<br />") document.write("Line 4 : " &DateDiff("y",fromDate,toDate) & "<br />") document.write("Line 5 : " &DateDiff("d",fromDate,toDate) & "<br />") document.write("Line 6 : " &DateDiff("w",fromDate,toDate) & "<br />") document.write("Line 7 : " &DateDiff("ww",fromDate,toDate)& "<br />") document.write("Line 8 : " &DateDiff("h",fromDate,toDate) & "<br />") document.write("Line 9 : " &DateDiff("n",fromDate,toDate) & "<br />") document.write("Line 10 : "&DateDiff("s",fromDate,toDate) & "<br />") </script> </body> </html>
将其另存为.html并在Internet Explorer中执行时,上述脚本将产生以下结果:
Line 1 : 1 Line 2 : 4 Line 3 : 12 Line 4 : 365 Line 5 : 365 Line 6 : 52 Line 7 : 52 Line 8 : 8783 Line 9 : 527039 Line 10 : 31622340