Solved

finding the last day of a calendar month

Posted on 2008-10-07
5
443 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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