Home All Groups Group Topic Archive Search About

Create A 3-Day Window Between 2 Calendars

Author
1 Aug 2006 7:18 PM
JLuv
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.

Author
3 Aug 2006 2:59 AM
Ken Cox [Microsoft MVP]
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>


Show quoteHide quote
"JLuv" <JLuv***@gmail.com> wrote in message
news:1154459912.180238.117850@p79g2000cwp.googlegroups.com...
>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.
>
Author
3 Aug 2006 4:01 PM
JLuv
Sweet! Thanks!

This is a lot simpler than the function i was gonna create myself. lol


Ken Cox [Microsoft MVP] wrote:
Show quoteHide quote
> 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" <JLuv***@gmail.com> wrote in message
> news:1154459912.180238.117850@p79g2000cwp.googlegroups.com...
> >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.
> >