Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Day Of Week

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Just Me - 16 Mar 2008 16:01 GMT
.NET enumerates the day of the week as 0-6 ( Sunday to Saturday ). This
seems to remain the same regardless of the culture settings.

Just wondering if this is alterable is some way, and if not how you guys
work out for example, next Sunday.  I mean sure, I can create a function
which will allways return the number of days between today and sunday using
for example the day name and a select statement, but it seems too complex.

Any ideas on the simple approach ?
Just Me - 16 Mar 2008 16:18 GMT
Dont know if its the best way, but I solved it like this,

public static DateTime thisSunday(DateTime targetDate)

{

int realDay = 1;

if (targetDate.DayOfWeek == 0) realDay = 7; else realDay =
(int)targetDate.DayOfWeek;

return targetDate.AddDays(7 - realDay);

}

> .NET enumerates the day of the week as 0-6 ( Sunday to Saturday ). This
> seems to remain the same regardless of the culture settings.
[quoted text clipped - 6 lines]
>
> Any ideas on the simple approach ?
Stan - 16 Mar 2008 23:11 GMT
Hi

The problem is not that the enumeration is 0 - 6. The complication
arises because you apparently require a logically different result for
Sunday than for other days of the week.

According to your solution if targetDate is Monday to Saturday then
you want to return the date for the *next* Sunday whereas if
targetDate is Sunday then you want to return the date unaltered i.e.
*this* Sunday.

For example if the code were written thus:

   DateTime NextSunday(DateTime targetDate)
   {
       int dow = (int)targetDate.DayOfWeek;
       return targetDate.AddDays(7 - dow);
   }

the result would be the same as your solution except when targetDate
is Sunday, in which case you get next Sunday i.e. a week later.
Just Me - 21 Mar 2008 21:26 GMT
Correct !

Thanks for your input.

> Hi
>
[quoted text clipped - 17 lines]
> the result would be the same as your solution except when targetDate
> is Sunday, in which case you get next Sunday i.e. a week later.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.