Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

finding the last day of a calendar month

Posted on 2008-10-07
5
Medium Priority
?
448 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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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