I can't have first day Monday insted of Sunday

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bojan.pikl@gmail.com

    I can't have first day Monday insted of Sunday

    Hi, I am making a calendar. It is costum made and I would like to have
    the ability to choose the first day (Monday or Sunday). I know for the
    firstDayOfWeek, but I can't change it. What should I do?


    I tried this but it does not work (it is always Sunday):

    using System.Globaliz ation;
    ....
    CultureInfo culture = (CultureInfo)Cu ltureInfo.Curre ntCulture.Clone ();
    CultureInfo uiculture =
    (CultureInfo)Cu ltureInfo.Curre ntUICulture.Clo ne();
    if (day == "Monday")
    {
    culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Monda y;
    uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;

    }


    else
    {
    culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Sunda y;
    uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;

    }


    System.Threadin g.Thread.Curren tThread.Current Culture = culture;
    System.Threadin g.Thread.Curren tThread.Current UICulture = uiculture;


    The code works fine but it's always Sunday the first day of week. I
    would like to change this.
    And here is my code:

    int DayIndex;
    DateTime objDate=new DateTime(Year,M onth,Day);

    //First day of week.
    int StartDayIndex=( int)objDate.Day OfWeek;

    //Empty array days.
    for(int i=0; i<37; i++)
    days[i]=0;

    for(int i=0; i<31; i++)
    {
    DayIndex=(Start DayIndex+i);
    if(i < DateTime.DaysIn Month(Year,Mont h))
    {
    days[DayIndex]=(i+1);
    }
    else
    {
    days[DayIndex]=0;
    }

    }

  • Mel

    #2
    Re: I can't have first day Monday insted of Sunday

    This works for me. You need to assign the culture to your application.

    CultureInfo myCulture = new CultureInfo("en-US");
    myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
    Application.Cur rentCulture = myCulture;

    MessageBox.Show (Application.Cu rrurentCulture. DateTimeFormat. FirstDayOfWeek. ToString())
    shows Sunday.


    <bojan.pikl@gma il.comwrote in message
    news:1157095262 .479481.85010@p 79g2000cwp.goog legroups.com...
    Hi, I am making a calendar. It is costum made and I would like to have
    the ability to choose the first day (Monday or Sunday). I know for the
    firstDayOfWeek, but I can't change it. What should I do?
    >
    >
    I tried this but it does not work (it is always Sunday):
    >
    using System.Globaliz ation;
    ...
    CultureInfo culture = (CultureInfo)Cu ltureInfo.Curre ntCulture.Clone ();
    CultureInfo uiculture =
    (CultureInfo)Cu ltureInfo.Curre ntUICulture.Clo ne();
    if (day == "Monday")
    {
    culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Monda y;
    uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
    >
    }
    >
    >
    else
    {
    culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Sunda y;
    uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
    >
    }
    >
    >
    System.Threadin g.Thread.Curren tThread.Current Culture = culture;
    System.Threadin g.Thread.Curren tThread.Current UICulture = uiculture;
    >
    >
    The code works fine but it's always Sunday the first day of week. I
    would like to change this.
    And here is my code:
    >
    int DayIndex;
    DateTime objDate=new DateTime(Year,M onth,Day);
    >
    //First day of week.
    int StartDayIndex=( int)objDate.Day OfWeek;
    >
    //Empty array days.
    for(int i=0; i<37; i++)
    days[i]=0;
    >
    for(int i=0; i<31; i++)
    {
    DayIndex=(Start DayIndex+i);
    if(i < DateTime.DaysIn Month(Year,Mont h))
    {
    days[DayIndex]=(i+1);
    }
    else
    {
    days[DayIndex]=0;
    }
    >
    }
    >

    Comment

    • Claes Bergefall

      #3
      Re: I can't have first day Monday insted of Sunday

      The code works fine but it's always Sunday the first day of week. I
      would like to change this.
      And here is my code:
      >
      int DayIndex;
      DateTime objDate=new DateTime(Year,M onth,Day);
      >
      //First day of week.
      int StartDayIndex=( int)objDate.Day OfWeek;
      >
      //Empty array days.
      for(int i=0; i<37; i++)
      days[i]=0;
      >
      for(int i=0; i<31; i++)
      {
      DayIndex=(Start DayIndex+i);
      if(i < DateTime.DaysIn Month(Year,Mont h))
      {
      days[DayIndex]=(i+1);
      }
      else
      {
      days[DayIndex]=0;
      }
      >
      }
      I don't see how the above has anything to do with the FirstDayOfWeek
      property.
      DateTime.DayOfW eek has nothing to do with whatever the first day of the week
      is.

      I don't really understand what you're trying to do here. You're filling an
      array with...somethin g. For what purpose? What is the meaning of, for
      example, days[12]?
      If I run the above with todays date (sept 1, 2006) I would get the
      following:

      days[0]=0
      days[1]=0
      days[2]=0
      days[3]=0
      days[4]=0
      days[5]=1
      days[6]=2
      days[7]=3
      days[8]=4
      days[9]=5
      days[10]=6
      ....
      days[29]=25
      days[30]=26
      days[31]=27
      days[32]=28
      days[33]=29
      days[34]=30
      days[35]=0
      days[36]=0

      How are you building a calendar from this? What would you like the array to
      look like for todays date (sept 1, 2006)?

      /claes


      Comment

      • Claes Bergefall

        #4
        Re: I can't have first day Monday insted of Sunday

        That's not the problem. He's already assigning it to the application

        Application.Cur rentCulture = culture;
        is equivalent with
        System.Threadin g.Thread.Curren tThread.Current Culture = culture;


        /claes

        "Mel" <Mel.RemoveSpam @insdirect.comw rote in message
        news:u$n%23Mncz GHA.720@TK2MSFT NGP02.phx.gbl.. .
        This works for me. You need to assign the culture to your application.
        >
        CultureInfo myCulture = new CultureInfo("en-US");
        myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
        Application.Cur rentCulture = myCulture;
        >
        MessageBox.Show (Application.Cu rrurentCulture. DateTimeFormat. FirstDayOfWeek. ToString())
        shows Sunday.
        >
        >
        <bojan.pikl@gma il.comwrote in message
        news:1157095262 .479481.85010@p 79g2000cwp.goog legroups.com...
        >Hi, I am making a calendar. It is costum made and I would like to have
        >the ability to choose the first day (Monday or Sunday). I know for the
        >firstDayOfWeek , but I can't change it. What should I do?
        >>
        >>
        >I tried this but it does not work (it is always Sunday):
        >>
        >using System.Globaliz ation;
        >...
        >CultureInfo culture = (CultureInfo)Cu ltureInfo.Curre ntCulture.Clone ();
        >CultureInfo uiculture =
        >(CultureInfo)C ultureInfo.Curr entUICulture.Cl one();
        >if (day == "Monday")
        >{
        > culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Monda y;
        > uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
        >>
        >}
        >>
        >>
        >else
        >{
        > culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Sunda y;
        > uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
        >>
        >}
        >>
        >>
        >System.Threadi ng.Thread.Curre ntThread.Curren tCulture = culture;
        >System.Threadi ng.Thread.Curre ntThread.Curren tUICulture = uiculture;
        >>
        >>
        >The code works fine but it's always Sunday the first day of week. I
        >would like to change this.
        >And here is my code:
        >>
        >int DayIndex;
        >DateTime objDate=new DateTime(Year,M onth,Day);
        >>
        >//First day of week.
        >int StartDayIndex=( int)objDate.Day OfWeek;
        >>
        >//Empty array days.
        >for(int i=0; i<37; i++)
        > days[i]=0;
        >>
        >for(int i=0; i<31; i++)
        >{
        > DayIndex=(Start DayIndex+i);
        > if(i < DateTime.DaysIn Month(Year,Mont h))
        > {
        > days[DayIndex]=(i+1);
        > }
        >else
        > {
        > days[DayIndex]=0;
        > }
        >>
        >}
        >>
        >
        >

        Comment

        • Mel

          #5
          Re: I can't have first day Monday insted of Sunday

          I beg to differ this also works

          CultureInfo myCulture = new CultureInfo("en-US");
          myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
          Application.Cur rentCulture = myCulture;

          MessageBox.Show (Application.Cu rrentCulture.Da teTimeFormat.Fi rstDayOfWeek.To String());
          // shows Monday







          "Claes Bergefall" <louplou@nospam .nospamwrote in message
          news:%23mymnwdz GHA.2300@TK2MSF TNGP05.phx.gbl. ..
          That's not the problem. He's already assigning it to the application
          >
          Application.Cur rentCulture = culture;
          is equivalent with
          System.Threadin g.Thread.Curren tThread.Current Culture = culture;
          >
          >
          /claes
          >
          "Mel" <Mel.RemoveSpam @insdirect.comw rote in message
          news:u$n%23Mncz GHA.720@TK2MSFT NGP02.phx.gbl.. .
          >This works for me. You need to assign the culture to your application.
          >>
          > CultureInfo myCulture = new CultureInfo("en-US");
          > myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
          > Application.Cur rentCulture = myCulture;
          >>
          >MessageBox.Sho w(Application.C urrurentCulture .DateTimeFormat .FirstDayOfWeek .ToString())
          >shows Sunday.
          >>
          >>
          ><bojan.pikl@gm ail.comwrote in message
          >news:115709526 2.479481.85010@ p79g2000cwp.goo glegroups.com.. .
          >>Hi, I am making a calendar. It is costum made and I would like to have
          >>the ability to choose the first day (Monday or Sunday). I know for the
          >>firstDayOfWee k, but I can't change it. What should I do?
          >>>
          >>>
          >>I tried this but it does not work (it is always Sunday):
          >>>
          >>using System.Globaliz ation;
          >>...
          >>CultureInfo culture = (CultureInfo)Cu ltureInfo.Curre ntCulture.Clone ();
          >>CultureInfo uiculture =
          >>(CultureInfo) CultureInfo.Cur rentUICulture.C lone();
          >>if (day == "Monday")
          >>{
          >> culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Monda y;
          >> uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
          >>>
          >>}
          >>>
          >>>
          >>else
          >>{
          >> culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Sunda y;
          >> uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
          >>>
          >>}
          >>>
          >>>
          >>System.Thread ing.Thread.Curr entThread.Curre ntCulture = culture;
          >>System.Thread ing.Thread.Curr entThread.Curre ntUICulture = uiculture;
          >>>
          >>>
          >>The code works fine but it's always Sunday the first day of week. I
          >>would like to change this.
          >>And here is my code:
          >>>
          >>int DayIndex;
          >>DateTime objDate=new DateTime(Year,M onth,Day);
          >>>
          >>//First day of week.
          >>int StartDayIndex=( int)objDate.Day OfWeek;
          >>>
          >>//Empty array days.
          >>for(int i=0; i<37; i++)
          >> days[i]=0;
          >>>
          >>for(int i=0; i<31; i++)
          >>{
          >> DayIndex=(Start DayIndex+i);
          >> if(i < DateTime.DaysIn Month(Year,Mont h))
          >> {
          >> days[DayIndex]=(i+1);
          >> }
          >>else
          >> {
          >> days[DayIndex]=0;
          >> }
          >>>
          >>}
          >>>
          >>
          >>
          >
          >

          Comment

          • bojan.pikl@gmail.com

            #6
            Re: I can't have first day Monday insted of Sunday

            Hi all,
            thanks for your replays.

            @Mel: Yes your code does work, and I figured out that mineprobably
            works too.

            @Claes Bergefall: I am filling an array that is later displayed on 37
            labels. This is plugin for a special skinable application, that is why
            it is done that way.

            Problem is that the dayOfWeek, will give 0 for Sunday, no mater what is
            firstDayOfWeek set to (at least as far as I can see). So I just make a
            small if statement wich looks if it is Monday the first and then
            decreses the variable that dayOfWeek set, otherwise it just lives as it
            is.

            Best Regads,
            Bojan

            Comment

            • Claes Bergefall

              #7
              Re: I can't have first day Monday insted of Sunday

              Problem is that the dayOfWeek, will give 0 for Sunday, no mater what is
              firstDayOfWeek set to (at least as far as I can see). So I just make a

              Yes, that is correct. The DayOfWeek property returns a DayOfWeek enum. Since
              it's an enum it has constant values, were (in this case) 0 means Sunday and
              6 means Saturday. This is documented in the Remarks section for the
              DayOfWeek enum. FirstDayOfWeek does not affect it.

              small if statement wich looks if it is Monday the first and then
              decreses the variable that dayOfWeek set, otherwise it just lives as it
              is.
              /claes


              Comment

              • Claes Bergefall

                #8
                Re: I can't have first day Monday insted of Sunday

                Hmm, not sure what you "beg to differ" about. My statement that
                Application.Cur rentCulture = culture;
                is equivalent with
                System.Threadin g.Thread.Curren tThread.Current Culture = culture;
                is easy to verify by checking the code for the Application.Cur rentCulture
                property.

                But yes, your code works too. I never said it didn't. I said that the OP was
                already assigning it to the application (by setting the current thread
                culture) so that was not the problem.

                /claes

                "Mel" <Mel.RemoveSpam @insdirect.comw rote in message
                news:%23I8MADgz GHA.3464@TK2MSF TNGP03.phx.gbl. ..
                >I beg to differ this also works
                >
                CultureInfo myCulture = new CultureInfo("en-US");
                myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
                Application.Cur rentCulture = myCulture;
                >
                MessageBox.Show (Application.Cu rrentCulture.Da teTimeFormat.Fi rstDayOfWeek.To String());
                // shows Monday
                >
                >
                >
                >
                >
                >
                >
                "Claes Bergefall" <louplou@nospam .nospamwrote in message
                news:%23mymnwdz GHA.2300@TK2MSF TNGP05.phx.gbl. ..
                >That's not the problem. He's already assigning it to the application
                >>
                >Application.Cu rrentCulture = culture;
                >is equivalent with
                >System.Threadi ng.Thread.Curre ntThread.Curren tCulture = culture;
                >>
                >>
                > /claes
                >>
                >"Mel" <Mel.RemoveSpam @insdirect.comw rote in message
                >news:u$n%23Mnc zGHA.720@TK2MSF TNGP02.phx.gbl. ..
                >>This works for me. You need to assign the culture to your application.
                >>>
                >> CultureInfo myCulture = new CultureInfo("en-US");
                >> myCulture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
                >> Application.Cur rentCulture = myCulture;
                >>>
                >>MessageBox.Sh ow(Application. CurrurentCultur e.DateTimeForma t.FirstDayOfWee k.ToString())
                >>shows Sunday.
                >>>
                >>>
                >><bojan.pikl@g mail.comwrote in message
                >>news:11570952 62.479481.85010 @p79g2000cwp.go oglegroups.com. ..
                >>>Hi, I am making a calendar. It is costum made and I would like to have
                >>>the ability to choose the first day (Monday or Sunday). I know for the
                >>>firstDayOfWe ek, but I can't change it. What should I do?
                >>>>
                >>>>
                >>>I tried this but it does not work (it is always Sunday):
                >>>>
                >>>using System.Globaliz ation;
                >>>...
                >>>CultureInf o culture = (CultureInfo)Cu ltureInfo.Curre ntCulture.Clone ();
                >>>CultureInf o uiculture =
                >>>(CultureInfo )CultureInfo.Cu rrentUICulture. Clone();
                >>>if (day == "Monday")
                >>>{
                >>> culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Monda y;
                >>> uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Monda y;
                >>>>
                >>>}
                >>>>
                >>>>
                >>>else
                >>>{
                >>> culture.DateTim eFormat.FirstDa yOfWeek = DayOfWeek.Sunda y;
                >>> uiculture.DateT imeFormat.First DayOfWeek = DayOfWeek.Sunda y;
                >>>>
                >>>}
                >>>>
                >>>>
                >>>System.Threa ding.Thread.Cur rentThread.Curr entCulture = culture;
                >>>System.Threa ding.Thread.Cur rentThread.Curr entUICulture = uiculture;
                >>>>
                >>>>
                >>>The code works fine but it's always Sunday the first day of week. I
                >>>would like to change this.
                >>>And here is my code:
                >>>>
                >>>int DayIndex;
                >>>DateTime objDate=new DateTime(Year,M onth,Day);
                >>>>
                >>>//First day of week.
                >>>int StartDayIndex=( int)objDate.Day OfWeek;
                >>>>
                >>>//Empty array days.
                >>>for(int i=0; i<37; i++)
                >>> days[i]=0;
                >>>>
                >>>for(int i=0; i<31; i++)
                >>>{
                >>> DayIndex=(Start DayIndex+i);
                >>> if(i < DateTime.DaysIn Month(Year,Mont h))
                >>> {
                >>> days[DayIndex]=(i+1);
                >>> }
                >>>else
                >>> {
                >>> days[DayIndex]=0;
                >>> }
                >>>>
                >>>}
                >>>>
                >>>
                >>>
                >>
                >>
                >
                >

                Comment

                Working...