p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Using month & year variable to get date in range (http://p2p.wrox.com/showthread.php?t=69163)

rsearing July 4th, 2008 06:33 PM

Using month & year variable to get date in range
I have an "Event" table where I am going to be storing dates. I then have a calendar control and want to "select" or "highlight" the dates from my table that relate to the month chosen. I know how to do this with something like:

For Each tdate As Date In testDates

My question is - how can I:

a) tie into the month changing event
b) grab the current month and year of the calendar control
c) use these to query the event table to only get events in the month and year passed to it?

THANKS!! - in the past, I never used "dates" but would store integers to store month, day and year - but would wind up writing too much custom code to work with dates where I think it would be easier to just store the date in the table.


rsearing July 4th, 2008 08:39 PM

Ok, I figured out how to get the month and day - and have to use two different events to get them based upon if it's the first time the page loads or if selected month is changed...so, for the first time, I put the following in Page_Load and do a If Not page.ispostback--for the other I put it in the event if selectedmonthchanged.

 Dim month As Integer = Calendar1.VisibleDate.Year.ToString
 Dim year As Integer = Calendar1.VisibleDate.Month.ToString

Now - I can pass these as parameters to a SQL statment - but not sure how to work it to pull only those months in the month and year passed. This is probably, now, more of a TSQL question than ASP - but could sure use the help if someone knows.

Many Thanks,

rsearing July 5th, 2008 08:30 AM

I can't tell you how many times a good nights sleep has helped me to solve a problem. Below is my function and SQL:

Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
        Dim month As Integer = Calendar1.VisibleDate.Month.ToString
        Dim year As Integer = Calendar1.VisibleDate.Year.ToString

        Dim myEventDates As New List(Of Date)
        Dim myEvents As New CAGEventList
        myEvents = CAGEventDB.GetEventDates(month, year)
        If Not myEvents Is Nothing Then
            For Each myCAGEVent As CAGEvent In myEvents

            For Each myDate As Date In myEventDates
        End If
    End Sub

NOTE: I have something similar in Page_Load to capture the calendar when page first loads. Since the calendar will always show current month I simply change my variables to:
Dim month As Integer = Date.Today.Month
Dim year As Integer = Date.Today.Year

Then, here is my SQL statement:

ALTER PROCEDURE dbo.sprocCAGEventGetEventListByMonthAndYear

    @myMonth integer,
    @myYear integer


        MONTH(eventDate)=@myMonth AND YEAR(eventDate)=@myYear


All times are GMT -4. The time now is 09:50 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.