ASP/VbScript DateDiff() ฟังก์ชั่นในการเปรียบเทียบวันที่และเวลา
Syntax
<%
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
%>
Interval
Setting |
Description |
yyyy |
Year |
q |
Quarter |
m |
Month |
y |
Day of year |
d |
Day |
w |
Weekday |
ww |
Week of year |
h |
Hour |
n |
Minute |
s |
Second |
firstdayofweek
Constant |
Value |
Description |
vbUseSystemDayOfWeek |
0 |
Use National Language Support (NLS) API setting. |
vbSunday |
1 |
Sunday (default) |
vbMonday |
2 |
Monday |
vbTuesday |
3 |
Tuesday |
vbWednesday |
4 |
Wednesday |
vbThursday |
5 |
Thursday |
vbFriday |
6 |
Friday |
vbSaturday |
7 |
Saturday |
firstweekofyear
Constant |
Value |
Description |
vbUseSystem |
0 |
Use National Language Support (NLS) API setting. |
vbFirstJan1 |
1 |
Start with the week in which January 1 occurs (default). |
vbFirstFourDays |
2 |
Start with the week that has at least four days in the new year. |
vbFirstFullWeek |
3 |
Start with the first full week of the new year. |
Sample
<%
Response.write Date&"<br>"
Response.write DateDiff("d","09/01/2008","09/04/2008")&"<br>"
Response.write DateDiff("m","09/01/2008","11/04/2008")&"<br>"
Response.write DateDiff("n","08:30","12:00")&"<br>"
Response.write DateDiff("h","08:30","15:30")&"<br>"
%>
Output
Reference : http://msdn.microsoft.com/en-us/library/xhtyw595(VS.85).aspx