After selecting the starting month of a fiscal year I need 2 fields to be completed automatically.

Claude Larocque 666 Reputation points
2022-03-29T13:29:15.743+00:00

Hi,
A user select May at the starting month of his business starting fiscal year. So the fiscal year will always be from May 1 to Apr 30. (FYFirstDate and FYLastDate)
I have in my datagridview named "FiscalYearDGV" 2 columns that gives me these information, however, I need to retrieve that row where the first column shows 4/30/2023 so I can use these 2 columns named "calendar_name_month_short" and "calendar_day_in_month" to complete these 2 fields. The first date is the first row so it should be easy, but the FYLastDate is what I need.

Here is an image that gives you more information:

187880-fiscalyear2fields.jpg

Developer technologies | VB
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LesHay 7,141 Reputation points
    2022-03-29T14:37:49.593+00:00

    Hi
    Is this of any help?

    From any date (TakeADate), get FYstartDate and FYlastDate:

    If you are starting with a TextBox Date as a String then
    TakeADate = CDate(TextBox1.Text). In any case, starting with a valid Date:

            ' take any date
            Dim TakeADate As Date = Now.AddMonths(-1).Date
    
            ' make start date with same month and year
            Dim FYstartDate As Date = New Date(TakeADate.Year, TakeADate.Month, 1)
    
            ' find last day
            Dim FYlastDate As Date = FYstartDate.AddMonths(1).AddDays(-1)
    
            ' find days in a month
            Dim DaysInMonth As Integer = DateTime.DaysInMonth(TakeADate.Year, TakeADate.Month)
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.