Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:09:18+00:00 2026-06-05T22:09:18+00:00

Possible Duplicate: Getting specific days in a month I’ve touched on this problem once

  • 0

Possible Duplicate:
Getting specific days in a month

I’ve touched on this problem once before, in How to find the 3rd Friday in a month with C#? But since I did not explain my problem well then, I must try again:

My goal here is simple: upon the press of a button (referred to here as “Button1”), I must determine whether today’s date is prior to either the first, or the third Wednesday of the month. If this is the case, I must then set the text of a label (referred to here as “lblDate”) to the date of whichever of these future Wednesdays is nearest to the current date.

So far, I’ve written this:

protected void Button1_Click(object sender, EventArgs e)
{

    DateTime Now = DateTime.Today;
    DateTime TempDate = new DateTime(Now.Year, Now.Month, 1);

    if (TempDate.DayOfWeek != DayOfWeek.Wednesday)
    {
        TempDate = TempDate.AddDays(1);
        string date = TempDate.ToString();
        lblDate.Text = date;
    }
    if (TempDate == TempDate.AddDays(1))
    {
        TempDate = TempDate.AddDays(14);
        string date = TempDate.ToString();
        lblDate.Text = date;
    }

}

As you can see, something is missing. I would greatly appreciate any assistance in filling that in…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:09:20+00:00Added an answer on June 5, 2026 at 10:09 pm

    You could also try it like this:

    protected DateTime getFirstWednesdayOfMonth(DateTime seedDate)
    {
        DateTime wed1 = new DateTime(seedDate.Year, seedDate.Month, 1); //1st Wednesday can start on the 1st of the month
        while (wed1.DayOfWeek != DayOfWeek.Wednesday)
        {
            wed1 = wed1.AddDays(1);
        }
        return wed1;
    }
    
    protected DateTime getThirdWednesdayOfMonth(DateTime seedDate)
    {
        DateTime wed3 = new DateTime(seedDate.Year, seedDate.Month, 15); //3rd Wednesday cannot start prior to the 15th of the month
        while (wed3.DayOfWeek != DayOfWeek.Wednesday)
        {
            wed3 = wed3.AddDays(1);
        }
        return wed3;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime Now = DateTime.Today;
        DateTime wed1 = getFirstWednesdayOfMonth(Now);
        DateTime wed3 = getThirdWednesdayOfMonth(Now);
    
        if (Now < wed1)
        {
            lblDate.Text = wed1.ToString();
        }
        else if (Now < wed3)
        {
            lblDate.Text = wed3.ToString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: NoClassDefFoundError - Eclipse and Android I'm seeing this question is getting asked
Possible Duplicate: getting identity row value using ADO.NET Entity This is my example code:
Possible Duplicate: Getting exception as “Collection was mutated while being enumerated” This question is
Possible Duplicate: Problem getting Facebook pictures via iOS How to get user's facebook profile
Possible Duplicate: malloc.c:3074 error? I am getting this strange error on execution of my
Possible Duplicate: Getting Cross-thread operation not valid Cross-thread operation not valid I am trying
Possible Duplicate: Getting a FILE* from a std::fstream Is there a way to obtain
Possible Duplicate: Getting the timestamp from last saturday (every week)? If today is Sunday,
Possible Duplicate: ConcurrentModificationException and a HashMap I am getting the following exception Exception in
Possible Duplicate: Compare dates in java I am getting two dates from server in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.