| | |
ToString to Display day of the week
Please support our C# advertiser: Intel Parallel Studio Home
Thread 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:
[
C# Syntax (Toggle Plain Text)
<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 12:05 pm.
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
Posts: 1
Reputation:
Solved Threads: 1
Try this:
If it's a weekday, it returns true, otherwise false.
C# Syntax (Toggle Plain Text)
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 1:11 pm. Reason: added comment
•
•
Join Date: Dec 2006
Posts: 39
Reputation:
Solved Threads: 0
•
•
•
•
Try this:
C# Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime decryption degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox listener mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update uploadatextfile usercontrol users validation view visualstudio webbrowser whileloop windows winforms wpf xml





