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 6747579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:27:39+00:00 2026-05-26T12:27:39+00:00

I have a specific problem with my calendar I’m making. Its difficult to explain

  • 0

I have a specific problem with my calendar I’m making. Its difficult to explain but By determining the week#(of the month) and the dayofweek i make a grid. The dates are not lining up the right way. Example: October 1, 2011 should begin on a saturday, since the 1st is in week 1 but starts on a saturday, the calendar should look something like this: (assuming there’s grid squares for each day) Iknow why this problem is occuring I just don’t know how to fix it. The dates are not lining up where they should on the grid.

Calendar should look like this:

   Columns       October 2011    grid.column = 7 (0-6)  grid.row = 6 (0-5) (Sunday-Saturday)

     Sunday Monday Tuesday Wednesday Thursday Friday Saturday
row    0      1       2        3       4        5       6
0     ------------------------------------------------- 1st
1     2nd     3rd     4th     5th      6th-----------etc..--- 
2    --------------------------------------------etc...------
3    ------etc..---------------------------------------------
4    ---------------- 25th     26th    27th     28th    29th
5    30th     31st

But mine looks like this: (column 0-4 should be shifted down one row)

    Sunday Monday Tuesday Wednesday Thursday Friday Saturday
row    0      1       2        3       4        5       6
0     2nd     3rd     4th     5th      6th------------- 1st
1     9th     10th     11th   12th     13th-----------etc..--- 
2    --------------------------------------------etc...------
3    ------etc..------25th     26th    27th-----------------
4    30th     31st--- ---------------------     28th    29th
5    -------------

Code:

public SchedulePage(MainWindow parentForm)
{
    InitializeComponent();

    _parentForm = parentForm;

    // DateTime date = new DateTime(year, month, day);
    var t = new List<Schedule>();
    DateTime curr = DateTime.Now;
    DateTime newcurr = new DateTime(curr.Year, curr.Month, 1);
    var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
    var ms = cal.GetWeekOfYear(new DateTime(newcurr.Year, newcurr.Month, 1), System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday);

    for (var i = 1; newcurr.Month == curr.Month; newcurr = newcurr.AddDays(1))
    {
        var sched = new Schedule();
        var month_week = (newcurr.Day / 7) + 1;
        sched.MonthWeek = month_week.ToString();
        sched.Month = newcurr.Month.ToString();
        sched.Year = newcurr.Year.ToString();
        sched.day = newcurr.Day.ToString();
        sched.WeekOfYear = cal.GetWeekOfYear(newcurr, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString();
        sched.dayofweek = newcurr.DayOfWeek.ToString();
        t.Add(sched);

     /* if (newcurr.Day == 1 && (int)newcurr.DayOfWeek == 7)
        {
            int findspot = month_week - 1;

            //_parentForm.bindings.schedule.Add(new Schedule {
            //    WeekNo = month_week - findspot,
            //    WeekDay = (int)newcurr.DayOfWeek,
            //    day = newcurr.Day.ToString()
            //});
        } */

        _parentForm.bindings.schedule.Add(new Schedule {
            WeekNo = month_week - 1 ,
            WeekDay = (int)newcurr.DayOfWeek,
            day = newcurr.Day.ToString()
        });
    }
}
  • 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-05-26T12:27:40+00:00Added an answer on May 26, 2026 at 12:27 pm

    You are using (day / 7) + 1 to get the WeekNo in that month (Row No). This will be incorrect unless the month begins on a Sunday.

    Use the code found in this SO answer to get the correct week number in the month

    It creates an ExtensionMethod for the DateTime class, which you can then use by calling newcurr.GetWeekOfMonth()

    static class DateTimeExtensions {
        static GregorianCalendar _gc = new GregorianCalendar();
        public static int GetWeekOfMonth(this DateTime time) {
            DateTime first = new DateTime(time.Year, time.Month, 1);
            return time.GetWeekOfYear() - first.GetWeekOfYear() + 1;
        }
    
        static int GetWeekOfYear(this DateTime time) {
            return _gc.GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a small Calendar application with some specific functions for my userbase but
I have run into a bit of a problem here: I had a problem-specific
I have the problem that an specific step in Ant can only be executed
We have a problem in a specific server. All plus signs posted to the
I have a problem with a specific java client library. Here is the situation:
I have a specific case in mind, but the question applies in general too.
This is a very general question but it's based on a specific problem. I've
I have one specific problem and I don't know how to solve it. I
I have a specific problem with a bottleneck in my code that I would
I have a very specific problem here. I have a multi-dimensional array that I

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.