ToString to Display day of the week

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2007
Posts: 36
Reputation: cassyjack is an unknown quantity at this point 
Solved Threads: 0
cassyjack's Avatar
cassyjack cassyjack is offline Offline
Light Poster

ToString to Display day of the week

 
0
  #1
Jan 18th, 2007
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:

[
  1. <script Language="c#" runat="server">
  2. void Page_Load()
  3. {
  4.  
  5. DateTime CurrentTime;
  6. DateTime MyTime;
  7. CurrentTime = DateTime.Now;
  8. MyTime = DayOfWeek.Now;
  9. message1.Text = "<br>The current time is: " + CurrentTime;
  10. message2.Text = "<br>The Day of the week is: "+ MyTime.DayOfWeek.ToString();
  11. }
  12.  
  13. </script>
  14. <html>
  15. <head><title>Assignment2</title></head>
  16. <body>
  17. <h1>Assignment 2</h1>
  18. Cassandra Jackson ECT 310</a>
  19. <asp:label id="message1" runat="server"/>
  20. <asp:label id="message2" runat="server"/>
  21.  
  22. </body>
  23.  
  24. </html>
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 89
Reputation: TylerSBreton is an unknown quantity at this point 
Solved Threads: 3
TylerSBreton's Avatar
TylerSBreton TylerSBreton is offline Offline
Junior Poster in Training

Re: ToString to Display day of the week

 
0
  #2
Jan 19th, 2007
Shouldn't 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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 36
Reputation: cassyjack is an unknown quantity at this point 
Solved Threads: 0
cassyjack's Avatar
cassyjack cassyjack is offline Offline
Light Poster

Re: ToString to Display day of the week

 
0
  #3
Jan 19th, 2007
Thanks A Bunch It Worked.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 8
Reputation: Aun Muhammad is an unknown quantity at this point 
Solved Threads: 1
Aun Muhammad Aun Muhammad is offline Offline
Newbie Poster

Re: ToString to Display day of the week

 
0
  #4
Jan 23rd, 2007
you can do as follows:


mydate=system.date.now.date;
date sdate;
sdate=mydate.dayofweek(); /////it will return actual day e.g.
sunday, monday,etc
if (dayofweek==weekday)
/////do some thing

try it
best of luck
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1
Reputation: RichardCh is an unknown quantity at this point 
Solved Threads: 1
RichardCh RichardCh is offline Offline
Newbie Poster

Re: ToString to Display day of the week

 
0
  #5
Jan 30th, 2007
Try this:
  1. public static bool IsWeekday(DateTime dtInput)
  2. {
  3. return ((dtInput.DayOfWeek == DayOfWeek.Saturday) || (dtInput.DayOfWeek == DayOfWeek.Sunday)) ? false : true;
  4. }

If it's a weekday, it returns true, otherwise false.
Last edited by RichardCh; Jan 30th, 2007 at 1:11 pm. Reason: added comment
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 39
Reputation: Maidomax is an unknown quantity at this point 
Solved Threads: 0
Maidomax Maidomax is offline Offline
Light Poster

Re: ToString to Display day of the week

 
0
  #6
Jan 31st, 2007
Originally Posted by RichardCh View Post
Try this:
  1. public static bool IsWeekday(DateTime dtInput)
  2. {
  3. return ((dtInput.DayOfWeek == DayOfWeek.Saturday) || (dtInput.DayOfWeek == DayOfWeek.Sunday)) ? false : true;
  4. }

If it's a weekday, it returns true, otherwise false.
Simple.Nice.Works.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC