ASP.NET DateDiff() เปรียบเทียบวันที่เวลาระหว่าง เวลา1 และ เวลา2
Syntax
DateDiff(DateInterval,Date1,Date2)
DateInterval
DateInterval.Day
DateInterval.DayOfYear
DateInterval.Hour
DateInterval.Minute
DateInterval.Month
DateInterval.Quarter
DateInterval.Second
DateInterval.Weekday
DateInterval.WeekOfYear
DateInterval.Year
Sample
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Me.lblText1.Text = DateDiff(DateInterval.Day, Cdate("11/08/2008"),Cdate("11/09/2008"))
Me.lblText2.Text = DateDiff(DateInterval.Month, Cdate("11/08/2008"), Cdate("12/08/2008"))
Me.lblText3.Text = DateDiff(DateInterval.Year, Cdate("11/08/2008"), Cdate("11/08/2009"))
Me.lblText4.Text = DateDiff(DateInterval.Hour, Cdate("11/08/2008 09:00"), Cdate("11/08/2008 10:00"))
Me.lblText5.Text = DateDiff(DateInterval.Second, Cdate("09:00:45"), Cdate("09:00:50"))
Me.lblText6.Text = DateDiff(DateInterval.Minute, Cdate("09:00"), Cdate("09:10"))
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Label id="lblText1" runat="server"></asp:Label><br />
<asp:Label id="lblText2" runat="server"></asp:Label><br />
<asp:Label id="lblText3" runat="server"></asp:Label><br />
<asp:Label id="lblText4" runat="server"></asp:Label><br />
<asp:Label id="lblText5" runat="server"></asp:Label><br />
<asp:Label id="lblText6" runat="server"></asp:Label><br />
</form>
</body>
</html>
Screenshot
|