•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 391,906 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,583 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 5023 | Replies: 5 | Solved
![]() |
OK I had C/C++ programming classes a few years ago and now I'm taking a ASP.net class and programming in C#. I need a little help with an assingment. We have to create an if state to display text depending on if the day of the week is a weekday vs weekend. I was able to get the time to dispaly ok. This next step I was taking before I created my if conditions was to try and display the day of the Week. Which I am unable to do. Any help would be appreciated. Also I don't have a compiler to test my code. I was trying to view the errors in IE. I added a web.config file to the root of my directory but it still does not give my an error description. Not sure if I have it in the correct place.
Here is the code for my program:
[
Here is the code for my program:
[
<script Language="c#" runat="server">
void Page_Load()
{
DateTime CurrentTime;
DateTime MyTime;
CurrentTime = DateTime.Now;
MyTime = DayOfWeek.Now;
message1.Text = "<br>The current time is: " + CurrentTime;
message2.Text = "<br>The Day of the week is: "+ MyTime.DayOfWeek.ToString();
}
</script>
<html>
<head><title>Assignment2</title></head>
<body>
<h1>Assignment 2</h1>
Cassandra Jackson ECT 310</a>
<asp:label id="message1" runat="server"/>
<asp:label id="message2" runat="server"/>
</body>
</html> Shouldn't
I havent fiddled too much with the DateTime mechanism yet in C#, but this seems like it should work.
Regards,
Tyler S. Breton
MyTime = DayOfWeek.Now; be something like MyTime = (DateTime.Now);. Then you should be able to do MyTime.DayOfWeek since DayOfWeek is a property of the DateTime class, so should be called on an instance variable of that class. I havent fiddled too much with the DateTime mechanism yet in C#, but this seems like it should work.
Regards,
Tyler S. Breton
Last edited by TylerSBreton : Jan 19th, 2007 at 11:05 am.
Western New England College '08
Computer Science
Programming Lang's:
C, C#, Java, Lisp, MASM, Visual Basic 6
Computer Science
Programming Lang's:
C, C#, Java, Lisp, MASM, Visual Basic 6
•
•
Join Date: Jan 2007
Location: Islamabad , Pakistan
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 1
•
•
Join Date: Jan 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 1
Try this:
If it's a weekday, it returns true, otherwise false.
public static bool IsWeekday(DateTime dtInput)
{
return ((dtInput.DayOfWeek == DayOfWeek.Saturday) || (dtInput.DayOfWeek == DayOfWeek.Sunday)) ? false : true;
}If it's a weekday, it returns true, otherwise false.
Last edited by RichardCh : Jan 30th, 2007 at 12:11 pm. Reason: added comment
•
•
Join Date: Dec 2006
Location: Kikinda, Vojvodina, Serbia, Europe, Planet Earth
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
Try this:
public static bool IsWeekday(DateTime dtInput) { return ((dtInput.DayOfWeek == DayOfWeek.Saturday) || (dtInput.DayOfWeek == DayOfWeek.Sunday)) ? false : true; }
If it's a weekday, it returns true, otherwise false.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
- day in a calender (JSP)
- How Get Date of "First Day of Current Week" in JSP (JSP)
- please help me - extremely clueless :( (C++)
- Problems with switch statement (C++)
Other Threads in the C# Forum
- Previous Thread: Do you know NET 2.0 documentation tools?
- Next Thread: C# and ID3 tags


Linear Mode