Hi,
You need to use a timespan for that. Here's some sample code.
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim dtCal1 As DateTime
Dim dtCal2 As DateTime
Dim tmspan As TimeSpan
dtCal1 = Calendar1.SelectedDate
dtCal2 = Calendar2.SelectedDate
tmspan = dtCal1.Subtract(dtCal2)
Label1.Text = "The difference is " & _
tmspan.TotalDays.ToString & " day(s)."
End Sub
</script>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Days Difference</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:calendar id="Calendar1" runat="server"></asp:calendar>
<br />
<asp:calendar id="Calendar2" runat="server"></asp:calendar>
<br />
<asp:label id="Label1" runat="server"></asp:label>
<br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Calculate" /></div>
</form>
</body>
</html>
JLuv said:
I have 2 calendar controls right now and i know how to compare the
dates from the 2 calendars using DateTime.Compare(). But that only
returns -1, 0, or 1. Is there a function that returns the difference in
the number of days?
What I want to do is allow only a 3 day gap between the 2 calendars.