Solved

finding the last day of a calendar month

Posted on 2008-10-07
5
444 Views
Last Modified: 2012-06-27
hi,

i have a calendar control on my page.

in the dayrender function i want to do something on the last day of the month.

how can i go about finding the last day of the month where this is my day render function?
Private Sub RenderDay(ByVal e As System.Web.UI.WebControls.DayRenderEventArgs, ByVal monthOfYear As UKCaravanFinderUtils.enmAvailabilityMonths, ByVal calendar As Calendar)
        Dim monthDay As Integer
        Dim dayAvailability As Reflection.PropertyInfo = Nothing

        'firstly get the day of the month that we are working on
        monthDay = CInt(e.Day.DayNumberText)

        'if the day isn't in the month then hide the text by colouring the font
        'this occurs with the calendar as it shows the last few days of last month etc
        If Not (e.Day.Date.Month = Now.Month) Then
            e.Cell.ForeColor = Drawing.Color.White 'hide days outside of this month that get shown
        End If

        'if we haven't already then we get the month we are working on out of the db.
        If _availabilityMonth Is Nothing Then
            _availabilityMonth = BLHelper.GetCalendarMonthAvailability(CInt(hdnCaravanID.Value), monthOfYear)
        End If

        'we now dynamically construct the property name based on the day we are working on using reflection
        dayAvailability = _availabilityMonth.GetType.GetProperty("Day" + monthDay.ToString())

        'now we just need to style the cell based on the availability of that day.
        Select Case dayAvailability.GetValue(_availabilityMonth, Nothing)
            Case UKCaravanFinderUtils.enmCaravanAvailability.Available
                e.Cell.BackColor = Drawing.Color.Green
            Case UKCaravanFinderUtils.enmCaravanAvailability.Booked
                e.Cell.BackColor = Drawing.Color.Blue
            Case UKCaravanFinderUtils.enmCaravanAvailability.UnavailableToBook
                e.Cell.BackColor = Drawing.Color.Red
            Case UKCaravanFinderUtils.enmCaravanAvailability.UnconfirmedBooking
                e.Cell.BackColor = Drawing.Color.Yellow
        End Select

            'if last day opf the month we need to set the value of month to nothing so next month the values arent cached from this month
CODE NEEDED HERE
    End Sub
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 300 total points
ID: 22663617
To get the Last Day of any month:

Dim Year as Integer = 2008
Dim Month as Integer = 10 ' October

Dim lastDayofMonth As Integer = Date.DaysInMonth(Year, Month)

this returns 31 as the Last Day of October, 2008

AW
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 200 total points
ID: 22663860
I would think that you need a Date, and not an Integer:

        Dim firstDayOfMonth As New Date(2008, 10, 1)
        Dim lastDayOfMonth As Date = firstDayOfMonth.AddMonths(1).AddDays(-1)
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22665500
My lastDayOfMonth is the # of the last Day of the Month, hence an Integer, not the Date of the Last Day of the Month.

TheLearnedOne is correct if you want the *Date* of the end of the Month.  Mine is correct if all you need is the number of the last day of the month (so my code would return 31 for October of 2008, where TheLearnedOne's code would return the Date 10/31/2008)

AW
0
 

Author Closing Comment

by:scm0sml
ID: 31503991
yeah i did just need the day
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22671519
Glad to be of assistance.

AW
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question