Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

finding the last day of a calendar month

Posted on 2008-10-07
5
Medium Priority
?
446 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 1200 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 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

704 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