Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 4th, 2008, 06:33 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default 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.


Old July 4th, 2008, 08:39 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing

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,

Old July 5th, 2008, 08:30 AM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pull Month & Year from Date(dd/mm/yyyy) istcomnet Classic ASP Basics 2 April 22nd, 2008 06:22 PM
Finding nday of evry month within date range arnabghosh Classic ASP Professional 0 December 6th, 2007 01:42 AM
find days per month in a date range rojer MySQL 1 June 5th, 2007 07:36 PM
Month and Year to Date on a Report Mitch Access 2 February 20th, 2007 10:23 AM
Month() Year() questions eon ASP.NET 1.0 and 1.1 Basics 1 October 4th, 2003 04:12 AM

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