473,224 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 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 17803

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
21
by: .:mmac:. | last post by:
I have to update a page every week. I get the page ahead of time so I used the "scheduled includes" webbot in Frontpage only to find that I would have to refresh the page every week to have it...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
3
by: Steph. | last post by:
Hi, When I use the "Calendar.GetWeekOfYear" function (with "fr-BE" as CultureInfo and Monday as the first day of week) I get : Friday 31/12/2004 : week = 53
3
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the...
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.