get month first date and last date using my data

RAVI 1,056 Reputation points
2024-11-03T05:36:49.7333333+00:00

Hello

Example 1:-

My asp.net label1 show example April-2024

In Label2 I want to show 01-APR-2024

In Label3 I Want To Show 30-APR-2024

Example 2:-

My asp.net label1 show example September-2024

In Label2 I want to show 01-SEP-2024

In Label3 I Want To Show 30-SEP-2024

Example 3:-

My asp.net label1 show example October-2023

In Label2 I want to show 01-OCT-2023

In Label3 I Want To Show 31-OCT-2023

how to do so using asp.net C#

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,543 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 118.5K Reputation points
    2024-11-03T07:21:42.08+00:00

    Check an example:

    // some date, used to show the month and year in Label1:
    DateTime some_date = new DateTime( 2024, 9, 17 ); // 17-September-2024
    
    // for Label2:
    DateTime first_day = new DateTime( some_date.Year, some_date.Month, 1 ); // 1-September-2024
    
    // for Label3:
    DateTime last_day = first_day.AddMonths( 1 ).AddDays( -1 ); // 30-September-2024
    
    0 comments No comments

  2. Lan Huang-MSFT 30,071 Reputation points Microsoft Vendor
    2024-11-04T02:29:16.4533333+00:00

    Hi @RAVI,

    You can refer to the following code:

     Label1.Text = "April-2024";
     DateTime date = Convert.ToDateTime(Label1.Text);
     var firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
     Label2.Text = firstDayOfMonth.ToString("dd-MMM-yyyy");
     var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);
     Label3.Text = lastDayOfMonth.ToString("dd-MMM-yyyy");
    

    Output:

    User's image User's image User's image Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread


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.