Question : Find an algorythm to calculate weeks of a List<Datetime>

Hello,

I am trying to find something generic without any hacks or too many checks/if`s etc.. because my solution works 99% but there are too many "exceptions" so I try to start again and find something better/more clear code.

Task:

I have a List of Datetimes selected by a user from a startdate with datepicker and a enddate from datepicker. For example user selected 01.07.2010 as startdate and as enddate 22.07.2010.

So my List of Datetimes has this: 01.07..,02.07..,03.07.,04.07..........21.07.,22.07.2010

PSEUDO-Code to give you a start help :P and to give you another HINT:

The first week object and the last week object in the final List<Week> CAN always be different from the week objects within the first AND last week object in the final List<Week>.

The problem is find something generic when you can not compute the week object with a mutual algorythm you can apply for EVERY week.

Now have fun:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
var weekList = new List<Week>();
for( int i = 0; i < dateList.Count; i++) // Please do not consider the CurrentCulture because my firstDayOfWeek is ALWAYS MONDAY
{
     if(1 == (int)dateList[i].DayOfWeek) // When datetime in the dateList is a MONDAY (1)
     {
            
      }
      else // No MONDAY
       {

       }
}

[b]Week.cs:[/b]
public int WeekID {get;set;}
public List<Day> Days {get;set;}

[b]Day.cs:[/b]
public Datetime MeetingDate {get;set;}



Basing on my above dateList I should get this  List of Weeks as result:

Week1.Days:
01.07.2010
02.07.2010
03.07.2010
04.07.2010
Week2.Days:
05.07.2010
06.07.2010
07.07.2010
08.07.2010
09.07.2010
10.07.2010
11.07.2010
Week3.Days:
12.07.2010
13.07.2010
14.07.2010
15.07.2010
16.07.2010
17.07.2010
18.07.2010
Week4.Days:
19.07.2010
20.07.2010
21.07.2010
22.07.2010

How would you do the algo?


Answer : Find an algorythm to calculate weeks of a List<Datetime>

use:

USE sql_song1;
GO
exec sp_change_users_login 'Update_One', 'leon', 'leon';
go

This solution assusmes you created a SQL account named leon within the SQL server, not the OS!

The other solution sp_revlogin mentioned by me and rrjeagan17 has to do with internal SQL Sid. This stays the same between both servers when migrating accounts utilizing sp_help_revlogin. Lookat: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_25193164.html

Regards Marten
Random Solutions  
 
programming4us programming4us