PC Review


Reply
 
 
Just Me
Guest
Posts: n/a
 
      16th Mar 2008
..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 ?


 
Reply With Quote
 
 
 
 
Just Me
Guest
Posts: n/a
 
      16th Mar 2008
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);

}



"Just Me" <news.microsoft.com> wrote in message
news:%(E-Mail Removed)...
> .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 ?
>



 
Reply With Quote
 
Stan
Guest
Posts: n/a
 
      16th Mar 2008
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.
 
Reply With Quote
 
Just Me
Guest
Posts: n/a
 
      21st Mar 2008
Correct !

Thanks for your input.


"Stan" <(E-Mail Removed)> wrote in message
news:6f31b7c6-894f-415c-9f0c-(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert regular Date to Week Ending or Week Beginning Dates Sam H Microsoft Excel Misc 4 27th Jan 2010 03:27 PM
Work week or week view advancing to next week =?Utf-8?B?ZnMwOQ==?= Microsoft Outlook Calendar 7 13th Oct 2006 09:29 PM
Outlook calendar shows incorrect week number ie one week ahead =?Utf-8?B?V0FTRUVNIEtIQU4=?= Microsoft Outlook Calendar 1 20th Mar 2005 04:14 AM
Finding a week number from a given date - Custom Defined Week Numb =?Utf-8?B?V2VuZHk=?= Microsoft Access Form Coding 3 14th Feb 2005 10:49 PM
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outlook Microsoft ASP .NET 3 22nd Dec 2003 10:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:04 AM.