I can't have first day Monday insted of Sunday

B

bojan.pikl

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=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;
}

}
 
M

Mel

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.
 
C

Claes Bergefall

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=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
 
C

Claes Bergefall

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 said:
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.


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=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;
}

}

 
M

Mel

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 said:
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 said:
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.


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=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;
}

}


 
B

bojan.pikl

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
 
C

Claes Bergefall

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
 
C

Claes Bergefall

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 said:
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 said:
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 said:
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.


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=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;
}

}


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top