Solved

finding the last day of a calendar month

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP.Net Session State alternatives 3 30
VB.Net - For Loop Error 5 26
Create XML 5 34
Closing all open child forms. 4 23
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now