471,319 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Day of the Week

Hi!

I'm beginer in C# so excuse me on silly questions but i hawe to start somehow.

I want to get a name of the day in the Week generated from a number.

For instance i have variable named; int Day = 2;
and then i have another variable named; string DayOfWeek;

and now i want to set it like this:

DayOfWeek = WeekDay(Day);

but i don't know witch funktion can i use to do this? Can someone help me?

Thanks!

G.
Jan 16 '06 #1
5 17689

DayOfWeek day = (DayOfWeek)2; // Sun = 0, Mon = 1, Tue = 2
Console.WriteLine(System.Globalization.DateTimeFor matInfo.CurrentInfo.GetDayName(day));

There is also a DayNames array if you prefer.

Marc

Jan 16 '06 #2

I don't know if we understand eachother i need some funktion to convert me
integer value to string name of day. For instance

int dayName = 2;

string NameOfDay =
System.Globalization.DateTimeFormatInfo.CurrentInf o.GetDayName(dayName);

and i get
NameOfDay is Tuestay

That's all.

G.
"Marc Gravell" wrote:

DayOfWeek day = (DayOfWeek)2; // Sun = 0, Mon = 1, Tue = 2
Console.WriteLine(System.Globalization.DateTimeFor matInfo.CurrentInfo.GetDayName(day));

There is also a DayNames array if you prefer.

Marc

Jan 16 '06 #3
Which is pretty much what I posted - isn't it?

Your code won't currently compile because the GetDayName function (which
does this job) doesn't accept an int - it accepts a DayOfWeek (enum); all I
have done is add tje required cast between the integer and the enum (adding
a comment to explain).

You could, however, do this

int dayName = 2;
string NameOfDay =
System.Globalization.DateTimeFormatInfo.CurrentInf o.GetDayName((DayOfWeek)
dayName);

Which is almost identical to the code I posted, except without the comment!

So where are we not agreeing?

If you don't need to worry about international issues, you could even cheat
and use:

string NameOfDay = ((DayOfWeek)dayName).ToString();

But I wouldn't recommend it...

Marc

Jan 16 '06 #4
You are right.

It works!

Thanks!

G.

Bye
Jan 16 '06 #5
No problem

Marc
Jan 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by androtech | last post: by
7 posts views Thread by Shuffs | last post: by
9 posts views Thread by Ray | last post: by
3 posts views Thread by Steph. | last post: by
3 posts views Thread by Mal | last post: by
6 posts views Thread by aarklon | last post: by
10 posts views Thread by Jim | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.