Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

ASP.NET/C#: Numerical Day of the Week

In ASP.NET/C#, I use this to get the current hour:
Server.Time.ToString("%H")

Open in new window

How can I get the numerical day of the week as a number between 1 and 7 where 1 is Sunday and 7 is Saturday?
SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

ASKER

That gives me an error:
Error CS0103: The name 'Datetime' does not exist in the current context

I need something that will work with THIS same type of format:
Server.Time.ToString("%H")

Open in new window

*No Points*

DateTime is in the System namespace, so be sure to bring that in somehow.

e.g.

System.Datetime.Now.DayofWeek + 1

Open in new window


Use the +1 if you want to start at one. The DayOfWeek enum starts its values at zero (i.e. Sunday = 0).
Avatar of skij

ASKER

How can I do this without using the system interface?  
                   
For example, sometimes I need to access past dates, not just NOW, like this:
Print(PingPrevious.ClosingTime.ToString("%H"));

I am looking for a way to use this with .ToString(()
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial