473,322 Members | 1,736 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,322 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 17811

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.