|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Create A 3-Day Window Between 2 CalendarsI 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. 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. > 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. > >
Events fired from dynamically created controls-VB.net
Set property in user control Dynamic button event not firing C# Correct place to add an event handler in code? Literal control rendering empty Referencing a parent control from a child? Adding layout elements within custom control How to Persist Dynamic Rows within WebControls.Table? DropDownList -- setting by text? customizing the dropdown menu of combo box in asp.net |
|||||||||||||||||||||||