PC Review


Reply
Thread Tools Rate Thread

I can't have first day Monday insted of Sunday

 
 
bojan.pikl@gmail.com
Guest
Posts: n/a
 
      1st Sep 2006
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.Globalization;
....
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
CultureInfo uiculture =
(CultureInfo)CultureInfo.CurrentUICulture.Clone();
if (day == "Monday")
{
culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;

}


else
{
culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;

}


System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = 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,Month,Day);

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

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

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

}

 
Reply With Quote
 
 
 
 
Mel
Guest
Posts: n/a
 
      1st Sep 2006
This works for me. You need to assign the culture to your application.

CultureInfo myCulture = new CultureInfo("en-US");
myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
Application.CurrentCulture = myCulture;

MessageBox.Show(Application.CurrurentCulture.DateTimeFormat.FirstDayOfWeek.ToString())
shows Sunday.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.Globalization;
> ...
> CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
> CultureInfo uiculture =
> (CultureInfo)CultureInfo.CurrentUICulture.Clone();
> if (day == "Monday")
> {
> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>
> }
>
>
> else
> {
> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>
> }
>
>
> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
> System.Threading.Thread.CurrentThread.CurrentUICulture = 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,Month,Day);
>
> //First day of week.
> int StartDayIndex=(int)objDate.DayOfWeek;
>
> //Empty array days.
> for(int i=0; i<37; i++)
> days[i]=0;
>
> for(int i=0; i<31; i++)
> {
> DayIndex=(StartDayIndex+i);
> if(i < DateTime.DaysInMonth(Year,Month))
> {
> days[DayIndex]=(i+1);
> }
> else
> {
> days[DayIndex]=0;
> }
>
> }
>



 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      1st Sep 2006
> 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,Month,Day);
>
> //First day of week.
> int StartDayIndex=(int)objDate.DayOfWeek;
>
> //Empty array days.
> for(int i=0; i<37; i++)
> days[i]=0;
>
> for(int i=0; i<31; i++)
> {
> DayIndex=(StartDayIndex+i);
> if(i < DateTime.DaysInMonth(Year,Month))
> {
> days[DayIndex]=(i+1);
> }
> else
> {
> days[DayIndex]=0;
> }
>
> }


I don't see how the above has anything to do with the FirstDayOfWeek
property.
DateTime.DayOfWeek 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...something. 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


 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      1st Sep 2006
That's not the problem. He's already assigning it to the application

Application.CurrentCulture = culture;
is equivalent with
System.Threading.Thread.CurrentThread.CurrentCulture = culture;


/claes

"Mel" <(E-Mail Removed)> wrote in message
news:u$n%(E-Mail Removed)...
> This works for me. You need to assign the culture to your application.
>
> CultureInfo myCulture = new CultureInfo("en-US");
> myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
> Application.CurrentCulture = myCulture;
>
> MessageBox.Show(Application.CurrurentCulture.DateTimeFormat.FirstDayOfWeek.ToString())
> shows Sunday.
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.Globalization;
>> ...
>> CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
>> CultureInfo uiculture =
>> (CultureInfo)CultureInfo.CurrentUICulture.Clone();
>> if (day == "Monday")
>> {
>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>>
>> }
>>
>>
>> else
>> {
>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>
>> }
>>
>>
>> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
>> System.Threading.Thread.CurrentThread.CurrentUICulture = 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,Month,Day);
>>
>> //First day of week.
>> int StartDayIndex=(int)objDate.DayOfWeek;
>>
>> //Empty array days.
>> for(int i=0; i<37; i++)
>> days[i]=0;
>>
>> for(int i=0; i<31; i++)
>> {
>> DayIndex=(StartDayIndex+i);
>> if(i < DateTime.DaysInMonth(Year,Month))
>> {
>> days[DayIndex]=(i+1);
>> }
>> else
>> {
>> days[DayIndex]=0;
>> }
>>
>> }
>>

>
>



 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      1st Sep 2006
I beg to differ this also works

CultureInfo myCulture = new CultureInfo("en-US");
myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
Application.CurrentCulture = myCulture;

MessageBox.Show(Application.CurrentCulture.DateTimeFormat.FirstDayOfWeek.ToString());
// shows Monday







"Claes Bergefall" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> That's not the problem. He's already assigning it to the application
>
> Application.CurrentCulture = culture;
> is equivalent with
> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
>
>
> /claes
>
> "Mel" <(E-Mail Removed)> wrote in message
> news:u$n%(E-Mail Removed)...
>> This works for me. You need to assign the culture to your application.
>>
>> CultureInfo myCulture = new CultureInfo("en-US");
>> myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>> Application.CurrentCulture = myCulture;
>>
>> MessageBox.Show(Application.CurrurentCulture.DateTimeFormat.FirstDayOfWeek.ToString())
>> shows Sunday.
>>
>>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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.Globalization;
>>> ...
>>> CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
>>> CultureInfo uiculture =
>>> (CultureInfo)CultureInfo.CurrentUICulture.Clone();
>>> if (day == "Monday")
>>> {
>>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>>>
>>> }
>>>
>>>
>>> else
>>> {
>>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>>
>>> }
>>>
>>>
>>> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
>>> System.Threading.Thread.CurrentThread.CurrentUICulture = 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,Month,Day);
>>>
>>> //First day of week.
>>> int StartDayIndex=(int)objDate.DayOfWeek;
>>>
>>> //Empty array days.
>>> for(int i=0; i<37; i++)
>>> days[i]=0;
>>>
>>> for(int i=0; i<31; i++)
>>> {
>>> DayIndex=(StartDayIndex+i);
>>> if(i < DateTime.DaysInMonth(Year,Month))
>>> {
>>> days[DayIndex]=(i+1);
>>> }
>>> else
>>> {
>>> days[DayIndex]=0;
>>> }
>>>
>>> }
>>>

>>
>>

>
>



 
Reply With Quote
 
bojan.pikl@gmail.com
Guest
Posts: n/a
 
      2nd Sep 2006
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

 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      5th Sep 2006
> 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


 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      5th Sep 2006
Hmm, not sure what you "beg to differ" about. My statement that
Application.CurrentCulture = culture;
is equivalent with
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
is easy to verify by checking the code for the Application.CurrentCulture
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I beg to differ this also works
>
> CultureInfo myCulture = new CultureInfo("en-US");
> myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
> Application.CurrentCulture = myCulture;
>
> MessageBox.Show(Application.CurrentCulture.DateTimeFormat.FirstDayOfWeek.ToString());
> // shows Monday
>
>
>
>
>
>
>
> "Claes Bergefall" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> That's not the problem. He's already assigning it to the application
>>
>> Application.CurrentCulture = culture;
>> is equivalent with
>> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
>>
>>
>> /claes
>>
>> "Mel" <(E-Mail Removed)> wrote in message
>> news:u$n%(E-Mail Removed)...
>>> This works for me. You need to assign the culture to your application.
>>>
>>> CultureInfo myCulture = new CultureInfo("en-US");
>>> myCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>> Application.CurrentCulture = myCulture;
>>>
>>> MessageBox.Show(Application.CurrurentCulture.DateTimeFormat.FirstDayOfWeek.ToString())
>>> shows Sunday.
>>>
>>>
>>> <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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.Globalization;
>>>> ...
>>>> CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
>>>> CultureInfo uiculture =
>>>> (CultureInfo)CultureInfo.CurrentUICulture.Clone();
>>>> if (day == "Monday")
>>>> {
>>>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>>>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
>>>>
>>>> }
>>>>
>>>>
>>>> else
>>>> {
>>>> culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>>> uiculture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
>>>>
>>>> }
>>>>
>>>>
>>>> System.Threading.Thread.CurrentThread.CurrentCulture = culture;
>>>> System.Threading.Thread.CurrentThread.CurrentUICulture = 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,Month,Day);
>>>>
>>>> //First day of week.
>>>> int StartDayIndex=(int)objDate.DayOfWeek;
>>>>
>>>> //Empty array days.
>>>> for(int i=0; i<37; i++)
>>>> days[i]=0;
>>>>
>>>> for(int i=0; i<31; i++)
>>>> {
>>>> DayIndex=(StartDayIndex+i);
>>>> if(i < DateTime.DaysInMonth(Year,Month))
>>>> {
>>>> days[DayIndex]=(i+1);
>>>> }
>>>> else
>>>> {
>>>> days[DayIndex]=0;
>>>> }
>>>>
>>>> }
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dates Monday thru Sunday Chuck216 Microsoft Access 3 10th Feb 2009 07:21 PM
Calendar 7 (Monday to Sunday) not days not 6 days (Saturday+Sunday)How ?? Gerhard Silbermann Microsoft Outlook Calendar 2 16th Oct 2008 12:03 AM
Changing Monday to Sunday? =?Utf-8?B?U3V6aWU=?= Microsoft Outlook Calendar 2 22nd Jan 2005 09:31 PM
Changing Monday to Sunday? =?Utf-8?B?U3V6aWU=?= Microsoft Outlook Calendar 0 22nd Jan 2005 06:35 PM
First day of week is monday, not sunday! Morten Wennevik Microsoft C# .NET 2 4th Dec 2003 09:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:21 PM.